tags:

views:

37

answers:

3

I have the following snippet

cv_13221 IN OUT SYS_REFCURSOR,

and just want to get cv_13221 out of it.

I tried the following regex

cv_.*\s

but it fetches me

cv_13221 IN OUT

what can I do to make it stop at first occurrence of \s

I am trying this in regex buddy

+1  A: 

Use a reluctant Kleene closure instead of a greedy one. Usually this is the syntax for it:

cv_.*?\s

Usually, the Kleene closure operator (*) will match as much as possible. The reluctant Kleene closure operator (*?) matches as little as possible.

Welbog
+4  A: 

Try:

cv_\S+

The capital 'S' in '\S' means: match a non-space character. And the + means one or nore, of course. Or:

cv_\d+

when it's always digits that come after the underscore: best to be as specific as you can when dealing with regex.

Bart Kiers
+1 for providing the better alternative of being more specific in the regex. I personally avoid using .* myself where possible, unless I specifically want an entire line or whatnot.
Platinum Azure
@Platinum Azure: couldn't agree more!
Bart Kiers
+2  A: 

.* is greedy. it will grab as much as it can before upto the last space. try this:

cv_[^\s]*
akf