I have the following php function which i wrote a while ago. Now however, I'm moving some parsing/matching to the client side.
function artist_name_to_regex($art_name){
$regex_part = preg_quote($art_name);
$regex_part = preg_replace('('|\')', '.+', $regex_part);
$regex_part = preg_replace('/ /i', '\s?', $regex_part);
$regex_part = preg_replace('/(and|&|&|\+)/i', '(and|&|&|\+)', $regex_part);
return $regex_part;
}
I'd like to call it like this from js:
var regex = artist_name_to_regex('David & the Smokey Sea Horses!');
if(some_str.match(/regex/ig)){
alert('match found!');
}
I need to modify the top function so that it:
a) is written in javascript
b) returns a regex that will work with javascipt
'('|\')'
need to be'/../'
? As for'/(and|&|&|\+)/i'
,&
will match before&
, and it seems they are all single replacements as opposed to global. I'm no expert on php yet. Can you give specific examples of how you are trying to condition the regex?