AlliDeacon AlliDeacon - 6 months ago 7
Perl Question

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 :)

Answer

You are matching any char . any number of times * until non-space \S.

You want non-space one or more times:

/(#\S+)/;

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

Comments