hi to all regex expert

im reading regular expression but for me is a little bit tricky yet

and cant create a good output

here is a simple
<font face='airal'>hello world </font>

now it will remove <font face='arial'> and </font>
the only thing remain is hello world

its a little bit spoon feeding for me but it will help me understand more on the regular expresion

thanks for understanding

thanks

    $str = preg_replace('#<font[^>]>(.*)</font>#iUs', "\\1", $str);
    

      In going the regex route, and assuming you want the font content from any font tag:

      $str = preg_replace('#<font[^>]*>(.*?)</font>#is', "\\1", $str);
      

      If you want specific fonts tags (like the attribute face='arial'), simply substitue the negated character class [>]* with the attribute / value...

      $str = preg_replace('#<font face=\'arial\'>(.*?)</font>#is', "\\1", $str);
      

        thanks for explaining using regex now i will play more around on it to understand more

          You can read more about regex by checking out this site as well as this one, and you can also pick up this book. I would suggest getting your feet wet with the site links first. Then go for the book if you want to really get a better handle on how regex works.

            between what does #is stand for?

              In preg statements, the patterns are encapsulated by delimiters. In Perl Compatible Regular Expressions, delimiters can be any non-whitespace, non alpha-numeric ASCII character other than the backslash.

              The letters that immediately follow the closing delimiter (in this case as you see, both Nog and I chose # characters for delimiters), are called modifiers, which perform extra tasks to the pattern at hand.

              As well as the links I provided above, you can read more about PCRE here. Regex isn't necessarily hard per-say, but rather tricky and intimidating at first.. but in time, as you keep playing around with it, you'll see it isn't so bad once you get to know it more.

                Write a Reply...