![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help with grep and regex | raichlea | UNIX for Dummies Questions & Answers | 14 | 04-16-2008 08:25 AM |
| regex question | xiamin | Shell Programming and Scripting | 2 | 07-16-2007 04:40 AM |
| Regex | deepakpv | Shell Programming and Scripting | 6 | 03-28-2007 01:18 AM |
| Regex?? Please help | lunac | UNIX for Dummies Questions & Answers | 7 | 01-30-2007 10:13 AM |
| sed regex | Shakey21 | UNIX for Dummies Questions & Answers | 4 | 01-31-2002 06:16 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
regex in variable
Hello!
I have problems with syntax... I want a variable, that contains regex... is it possible? Like $ a='.+->.+' and then use it in index ($0, "a"). I guess it won't work... thank you |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Yes - use eval. For example, here I define a regex then use it with egrep
Code:
$ regex='.+->.+' $ echo -e "somestring->someotherstring\ndont_match_this" somestring->someotherstring dont_match_this $ echo -e "somestring->someotherstring\ndont_match_this" | eval egrep "\$regex" somestring->someotherstring ZB |
|
#3
|
|||
|
|||
|
Thank you!
I know, that must be simple, but I can't figure out , why it is not working... I need a regex, that finds strings like "Aaaa->Bbbbb" but not "Aaaa-> Bbbbb" I tried .+-+>+.+ but it finds also with spaces... and .+-+>+[A-Z]+ finds totally wrong... |
|
#4
|
||||
|
||||
|
Code:
$ echo 'Aaaa->Bbbbb' | egrep '.+-+>+[^ ]+' Aaaa->Bbbbb $ echo 'Aaaa-> Bbbbb' | egrep '.+-+>+[^ ]+' $ |
|
#5
|
|||
|
|||
|
Thanks
|
|||
| Google The UNIX and Linux Forums |