Regular expression to match the input string is "Chart for - FName MName LName(ID)" where FName, MName, LName and ID are alphanumric and can change at run time. for example it can be
chart for -Anshul Srivastava (10GF12)
chart for - Vidya sagar gupta(101)
chart for - Avul Pakir Jainulabdeen Abdul Kalam(1097F)
I am new to Regex and try to build as
/Chart for -/-\s[a-zA-Z0-9]+\s/\(([^)]+)\)$/
but it is not working.
There is no need to use any complex regex only to validate.
chart for -[\w\s]+\(\w*?\)$
In your regex you have capital C
(in Chart) this could be a problem.
try this,
/chart for -[a-z0-9 ()]+/i
your can use this link to test your regular expression with examples.
There are great sites that help you to validate your regexp for example http://regexpal.com/
If the example text you posted is really that unstructured this regexp will do it:
chart for -[A-Za-z ]*\([0-9A-Za-z]*\)
If it's a bit more structured, like always a space after the first -
and before the ( )
then you also could make the regexp a bit more precise.
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.