Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
XML
Hi.

I have string "? string:45dea2c1-70a5-4d79-8e67-03859965d58d ?" like this. I would like to get guid. How can i do

<pre lang="Javascript">
 var pattern = \? string:([a-zA-Z0-9_]) \?
 var value = "? string:45dea2c1-70a5-4d79-8e67-03859965d58d ?"
 var res = value.match(pattern)
</pre>

doesnot work
Posted

1 solution

A regex should be inside forward slashes, with backslashes to escape special characters like the question marks:
JavaScript
var pattern = /\? string:([a-zA-Z0-9-]+) \?/;

I've replaced the underscore (_) with a hyphen (-) to match that inside the GUID, and added the "+" at the end to match at least one character. value.match(pattern) will return an array containing the full string and the GUID.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900