Regular expression for matching words containing underscore _character

R

Raj

I have large text passages containing names of database tables,
procedures, packages, variables etc having the underscore character as
a part of the name. eg. rsp_names_friends_master. I tried "\b[a-zA-
Z0-9_]+\b" but it matches all words in the passage.

Thanks in advance for the help.

Raj
 
R

RedGrittyBrick

Raj said:
I have large text passages containing names of database tables,
procedures, packages, variables etc having the underscore character as
a part of the name. eg. rsp_names_friends_master. I tried "\b[a-zA-
Z0-9_]+\b" but it matches all words in the passage.

Similarly "[ab]+" matches "aaa" and "aa" though neither contain "b".

Try "\b[a-zA-Z0-9]+_[a-zA-Z0-9_]+\b"

Or "\b\w+_\w+\b"
 
T

Tad J McClellan

RedGrittyBrick said:
Raj said:
I have large text passages containing names of database tables,
procedures, packages, variables etc having the underscore character as
a part of the name. eg. rsp_names_friends_master. I tried "\b[a-zA-
Z0-9_]+\b" but it matches all words in the passage.

Similarly "[ab]+" matches "aaa" and "aa" though neither contain "b".

Try "\b[a-zA-Z0-9]+_[a-zA-Z0-9_]+\b"

Or "\b\w+_\w+\b"


Three (six?) useless uses of word boundary in the quotes above...

Every pattern there will behave identically without any \b's.
 
R

Raj

Raj said:
I have large text passages containing names of database tables,
procedures, packages, variables etc having the underscore character as
a part of the name. eg. rsp_names_friends_master. I tried "\b[a-zA-
Z0-9_]+\b" but it matches all words in the passage.

Similarly "[ab]+" matches "aaa" and "aa" though neither contain "b".

Try "\b[a-zA-Z0-9]+_[a-zA-Z0-9_]+\b"

Or "\b\w+_\w+\b"

Thanks. It worked.
Raj
 
F

Florian Kaufmann

I have large text passages containing names of database tables,
procedures, packages, variables etc having the underscore character as
a part of the name. eg. rsp_names_friends_master. I tried "\b[a-zA-
Z0-9_]+\b" but it matches all words in the passage.

Thanks in advance for the help.

Raj

I would use this to merly find lines wich contain what you search
/\p{IsAlnum}+_)+\p{IsAlnum}+/

I would use this to get the words you search into an array
/((?:\p{IsAlnum}+_)+\p{IsAlnum}+)/g

Example:
perl -ne 'print @a if (@a = /((?:\p{IsAlnum}+_)+\p{IsAlnum}+)/g)' <<<
'yyy_yyy saf_;fasl asfd ; xxx_xxx'

Greetings

Flo
 
R

RedGrittyBrick

Tad said:
RedGrittyBrick said:
Raj said:
I have large text passages containing names of database tables,
procedures, packages, variables etc having the underscore character as
a part of the name. eg. rsp_names_friends_master. I tried "\b[a-zA-
Z0-9_]+\b" but it matches all words in the passage.
Similarly "[ab]+" matches "aaa" and "aa" though neither contain "b".

Try "\b[a-zA-Z0-9]+_[a-zA-Z0-9_]+\b"

Or "\b\w+_\w+\b"


Three (six?) useless uses of word boundary in the quotes above...

Every pattern there will behave identically without any \b's.

TFTC

$ perl -e 'print "$_\n" for "_aa-bbb.cc_[d_d]" =~ /\w+/g'
_aa
bbb
cc_
d_d

$ perl -e 'print "$_\n" for "_aa-bbb.cc_[d_d]" =~ /\w+_\w+/g'
d_d

In Perl programs I've written, I don't think I've ever used \b. Perhaps
I should have analyzed the OP's RE completely rather than only
commenting on the primary reason for the problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top