Page 1 of 1
Regular Expressions
Posted: Fri Mar 25, 2005 10:47 am
by Neo
I want to match a text pattern that may or may not have a CR or LF present in the middle of the string. It is of the form
. The .* here does not match patterns with CR or LF (which may or may not be present). How can I do this?
Re:Regular Expressions
Posted: Fri Mar 25, 2005 10:57 am
by mystran
eat characters until you can match the starting tag, then eat characters until you hit CR/LF or the ending tag.
For more information, read about finite state machines.
Re:Regular Expressions
Posted: Fri Mar 25, 2005 11:00 am
by Neo
I was wondering how to do it with egrep not from a programming language.
Re:Regular Expressions
Posted: Fri Mar 25, 2005 3:30 pm
by mystran
ah, ok.. and it seems I misread your original problem, as you seem to want to allow line terminators..
If I am not mistaken, you cannot have grep do that for you, since grep seems to always process it's input as line-by-line (somebody correct me if some variant of grep allows multiline matches). Depending what you want to do, you might be able to use 'sed' though (or if everything else fails, perl if ofcourse your friend
)
To match those patterns within one line, you can use simply
or whatever...
Re:Regular Expressions
Posted: Sat Mar 26, 2005 2:31 pm
by Neo
I think I should have a look at sed. Never used it before but it seems to be one way of doing it.