I have several Javascript strings (using jQuery). All of them follow the same pattern, starting with ‘ajax-‘, and ending with a name. For instance ‘ajax-first’, ‘ajax-last’, ‘ajax-email’, etc.
How can I make a regex to only grab the string after ‘ajax-‘?
So instead of ‘ajax-email’, I want just ’email’.
Given a comment you made on another user’s post, try the following:
Demo can be found here
Below kept for reference only
Use the
\w(word) pattern and bind it to the end of the string. This will force a grab of everything past the last hyphen (assuming the value consists of only [upper/lower]case letters, numbers or an underscore).The non-regex approach could also use the
String.splitmethod, coupled withArray.pop.