Hello
I am quite new to regular expression and I am faced with a challange that I feel could be solved quite easily using regular expression.
I would appreciate if someone could help me with the solution and if possible to explain how he/she solved it so I will pick up my regular expression knowledge.
Here is the problem:
I am given a PHP string like so:
$phrase = ‘Jo?n* Mil??er’
Where [b]except whitespace
and ? means a single occurance of any letter ([b]except whitespace
I then get another sentence (in another PHP string) in which the phrase was found. For example: ‘Johnny Miller was here’
I need to use regular expressions to highlight the phrase in the sentence (using the <b> tag).
So in the example above, the highlighted expression will be:
‘<b>Johnny Miller</b> was here’
Here is another example:
$phrase = ‘*a
$sentence = ‘The tall man walked down the street’
The highlighted sentecne will be:
‘The <b>tall</b> <b>man</b> <b>walked</b> down the street”
or in HTML:
‘The [b]tall[b]man[b]walked
I would appreciate any help
regards
Jason