[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Regular Expressions
"Pavel A. Romashkin" wrote:
> Wouldn't it be easier to analyse a byte array with more human-readible
> functions, than those beautiful regular expressions you guys brought up?
>
It depends on what you mean by "easier". One nice thing about STREGEX is
that it works on vector strings. One can always convert the string
array to a byte array and analyze, but -- **if you are trying to avoid
loops** -- the indexing can be become extremely opaque, and exercise at
least as many brain cells as using STREGEX. For example, JD's solution
can also apply to a string array where one is trying to extract the
substrings beginning and ending with a singe quote:
IDL> st = ["value1 = 'Wayne''s dog' / First string ", $
"value2 = 'Sue''s dog and Ralph''s cat' / Second string ", $
"value3 = 'two pigeons'" ]
IDL> val = (stregex(st, /SUBEXPR,/EXTRACT,"= *'(.*)'([^']|$)"))[1,*]
IDL> print,val
Wayne''s dog
Sue''s dog and Ralph''s cat
two pigeons
Of course, one should probably add an English comment to the use of STRGEX
; Find the substring beginning with an "=", followed by any number of
characters,
; followed by a quote, followed by any number of characters (including
double
; quotes) up to the last single quote. Extract from this substring all
; characters between the first and last single quotes.