Re: RegEx question

トップ ページ
添付ファイル:
Eメールのメッセージ
+ (text/plain)
+ (text/plain)
このメッセージを削除
このメッセージに返信
著者: der.hans
日付:  
To: Main PLUG discussion list
題目: Re: RegEx question
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:
> => person
> => me


Use parenthesis to create a back reference.

For sed it's important to use the -r flag for this.

$ echo | 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 | sed -re 's/@.+//'
person

In any case, you might want to search for not the delimiter rather than
any character.

$ echo person@email@.tld | sed -re 's/(.+)@.+/\1/'
person@email

$ echo person@email@.tld | 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 -
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss