简体   繁体   中英

PERL Regex help matching a string in a field

I currently have a field that looks like this.

item description is blah ablha blabh albhalbh #thisisitemnumber x/skid)

I am trying to extract the #thisisitemnumber portion. I currently have this:

'/(#.*\\S)/'

But using that I get everything after the "#" even the whitespace. Any help is appreciated!

Thanks :)

You are matching any char . any number of times * until non-space \\S . This isn't really what you want. Also, since * is greedy it scoops up everything up to the last non-space in the string.

You want non-space one or more times:

/(#\S+)/;

This presumes that there should be something after # , thus the +

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM