Regular expression

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
zerandib
Forum Newbie
Posts: 16
Joined: Tue Dec 16, 2008 12:17 am

Regular expression

Post by zerandib »

Moved by moderator to Regex forum.

Hello

$nametitle = "15658'>Tattoo funny cool</a></td><";

how can i remove these tags
</a></td><
and
'>

then how to get the out put as
15658
Tattoo funny cool


need help!
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Regular expression

Post by John Cartwright »

Regex not required. Take a look at strip_tags()
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: Regular expression

Post by prometheuzz »

A bit of an old thread, but here's a possible way to do it. As already mentioned, the tags can be removed by using the built-in strip_tags function. After doing so, you can split the string with a regex:

Code: Select all

$nametitle = "15658'>Tattoo funny cool</a></td><";
$tokens = preg_split("/[\"'<>]+/", strip_tags($nametitle), 2);
print_r($tokens);
The last parameter, the number two, will cause the split function to split the target string in no more than two sub-strings.
piyushj
Forum Newbie
Posts: 6
Joined: Thu Jan 15, 2009 10:40 am

Re: Regular expression

Post by piyushj »

regular expression for the only strings that are not generated over {a,b} by the expression (a+ b)* a (a+b)*
reasoning please
piyushj
Forum Newbie
Posts: 6
Joined: Thu Jan 15, 2009 10:40 am

Re: Regular expression

Post by piyushj »

Write a regular expression for strings that contain atleast one a and one b. show that its capable of generating the strings :

(i) aabbbabaa
(ii) bbbbaaa
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: Regular expression

Post by prometheuzz »

piyushj wrote:Write a regular expression for strings that contain atleast one a and one b. show that its capable of generating the strings :

(i) aabbbabaa
(ii) bbbbaaa
As I suggested three times now: create your own thread instead of hijacking other people's thread.
Post Reply