Am 17. Sep, 2009 schwätzte Paul Mooring so:
This is probably a really obvious question but how can I match
everything up to a character not including that character with regex?
For example:
[email protected] => person
[email protected] => me
Use parenthesis to create a back reference.
For sed it's important to use the -r flag for this.
$ echo [email protected] | sed -re 's/(.+)@.+/\1/'
person
If you're doing this in perl you can reference the match later.
If you're just trying to strip off the remainder it might be easier to do
that rather than pulling up the match.
$ echo [email protected] | sed -re 's/@.+//'
person
In any case, you might want to search for not the delimiter rather than
any character.
$ echo per...@[email protected] | sed -re 's/(.+)@.+/\1/'
per...@email
$ echo per...@[email protected] | sed -re 's/([...@]+)@.+/\1/'
person
ciao,
der.hans
--
# http://www.LuftHans.com/ http://www.ABLEconf.com/
# Director of Engineering, FonWallet Transaction Solutions, Inc.
# ABLEconf: Saturday, 2009Okt24, Tempe. Call for Presentations now open.
# If you have an apple and I have an apple and we exchange apples then
# you and I will still each have one apple. But if you have an idea and
# I have an idea and we exchange these ideas, then each of us will have
# two ideas. -- George Bernard Shaw
---------------------------------------------------
PLUG-discuss mailing list - [email protected]
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss