RuleBritannia Posted November 2, 2013 Share Posted November 2, 2013 Cant seem to find any solution to this String 1 'Let's all go on holiday : America' String 2 'Lets all go on holiday America' When doing a match for this string, I class this as acceptable, However a straight regex will not accept this, Because of the full colon and comma. What I want to achieve, is exactly a case insensitive search, but with some characters to be insensitive about. To ignore case you just append i to the end of your pattern. I want to pay no attention to ' :, if its there ok, if its not and the rest matchs ok Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/283524-big-problem/ Share on other sites More sharing options...
RuleBritannia Posted November 2, 2013 Author Share Posted November 2, 2013 Update. I just noticed one possible way this "may" be possible, havnt tested yet. What if I was to append a ? to each insensitive character in the string. This would tell regex to either find a , or : and match regardless. PS, If this does work, I would still like to hear your answer if you have alternatives, I believe there may be other ways to achieve this. Thanks all Link to comment https://forums.phpfreaks.com/topic/283524-big-problem/#findComment-1456565 Share on other sites More sharing options...
RuleBritannia Posted November 2, 2013 Author Share Posted November 2, 2013 Just a little update guys, I tested my above possible solution, and it worked, But I would appreciate some other alternatives as im sure there are some. Link to comment https://forums.phpfreaks.com/topic/283524-big-problem/#findComment-1456567 Share on other sites More sharing options...
ignace Posted November 2, 2013 Share Posted November 2, 2013 What is it exactly that you want to match? What is your current code? $regex = "/Let'?s all go on holiday (: )?America/i"; foreach (array("Let's all go on holiday : America", "Lets all go on holiday America") as $text) { if (preg_match($regex, $text, $matches)) { echo '<div style="color: green">' . $text . '</div>'; } else { echo '<div style="color: red">' . $text . '</div>'; } } Link to comment https://forums.phpfreaks.com/topic/283524-big-problem/#findComment-1456575 Share on other sites More sharing options...
RuleBritannia Posted November 2, 2013 Author Share Posted November 2, 2013 What is it exactly that you want to match? What is your current code? $regex = "/Let'?s all go on holiday (: )?America/i"; foreach (array("Let's all go on holiday : America", "Lets all go on holiday America") as $text) { if (preg_match($regex, $text, $matches)) { echo '<div style="color: green">' . $text . '</div>'; } else { echo '<div style="color: red">' . $text . '</div>'; } } The solution I just done works like this $search = 'Rule Britanni'a King of : All'; $ignore[0] = array(',',':'); $ignore[1] = array(',?',':?'); $string = str_replace($ignore[0],$ignore[1],$string); preg_match("/$string/i",$search,$match); var_dump($match); This actually works fine, But wondered if there are other solutions quicker/better then what I have done Link to comment https://forums.phpfreaks.com/topic/283524-big-problem/#findComment-1456636 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.