Chris Scott
Chris Scott

Reputation: 3

Find word after regex pattern match

I am using coldfusion's ReMatch() trying to find all filenames in a string that have a \ at the beginning. Not having much success.. here is my code so far.

<cfset fname='this is a \\green.png folder.  But this one is \\blue.jpg.'>
<cfset matchval=#ReMatch("\\\\\w+",fname)#>
<cfdump var="#matchval#">

Outputs \\green and \\blue.
I need green.png blue.jpg

Thanks in advance for the help... I'm sure a regex guru will know this right off.

Upvotes: 0

Views: 167

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174816

Just put \w, dot inside a character class and make it to repeat one or more times by adding + next to that character class.

<cfset matchval=#ReMatch("\\\\(\\w+\\.\\w+)",fname)#>

Finally print the index 1 value to get your desired string.

Upvotes: 1

Related Questions