Regex question.

Video Game Discussions and general topics.

Moderators: AArdvark, Ice Cream Jonsey

User avatar
pinback
Posts: 17849
Joined: Sat Apr 27, 2002 3:00 pm
Contact:

Regex question.

Post by pinback »

Why can't I figure this out...

I want to do WORD negation, instead of just character negation...

For instance, let's say I want to match any name which ISN'T "Ben", "Robb", or "Porkball"... something like...

/[^(Ben|Robb|Porkball)]/

...which doesn't work of course, but how do you do it?
Am I a hero? I really can't say. But, yes.

User avatar
pinback
Posts: 17849
Joined: Sat Apr 27, 2002 3:00 pm
Contact:

Post by pinback »

Or, I'll ask even more directly:

I want to strip out all HTML tags from a string EXCEPT for a few specific ones like <i> and <b> and whatnot...

How how how.
Am I a hero? I really can't say. But, yes.

k. roo
Posts: 168
Joined: Mon Sep 09, 2002 4:36 pm
Location: NJ

Post by k. roo »

pinback wrote:I want to strip out all HTML tags from a string EXCEPT for a few specific ones like <i> and <b> and whatnot...
perldoc HTML::Parser

Code: Select all

use HTML&#58;&#58;Parser;
$p = HTML&#58;&#58;Parser->new&#40; ... &#41;;
$p->ignore_tags&#40; @tags &#41;;
$p->ignore_elements&#40; @tags &#41;;

User avatar
pinback
Posts: 17849
Joined: Sat Apr 27, 2002 3:00 pm
Contact:

Post by pinback »

Okay, that's awesome. Now, how about if, say, I'm not using Perl?
Am I a hero? I really can't say. But, yes.

User avatar
Ice Cream Jonsey
Posts: 30069
Joined: Sat Apr 27, 2002 2:44 pm
Location: Colorado
Contact:

Post by Ice Cream Jonsey »

pinback wrote:Okay, that's awesome. Now, how about if, say, I'm not using Perl?
You never specified what you were using. Here, let me help -- let me tell you about FIND and REPLACE in a text editor.
the dark and gritty...Ice Cream Jonsey!

User avatar
pinback
Posts: 17849
Joined: Sat Apr 27, 2002 3:00 pm
Contact:

Post by pinback »

Ice Cream Jonsey wrote:You never specified what you were using.

It's regex. It's a common syntax. If you're not part of the solution, you're part of the problem.
Am I a hero? I really can't say. But, yes.

bruce
Posts: 2544
Joined: Tue Jun 04, 2002 10:43 pm

Post by bruce »

pinback wrote:
Ice Cream Jonsey wrote:You never specified what you were using.

It's regex. It's a common syntax. If you're not part of the solution, you're part of the problem.
Which fucking regex? Shell regular expressions are not Perl regular expressions. Java's got classes for both of 'em I think. GNU Extended Regular Expressions?

Throw us a bone here, or I'll either stop or start throwing a bone to your mom.

Bruce

User avatar
pinback
Posts: 17849
Joined: Sat Apr 27, 2002 3:00 pm
Contact:

Post by pinback »

Perl.
Am I a hero? I really can't say. But, yes.

bruce
Posts: 2544
Joined: Tue Jun 04, 2002 10:43 pm

Post by bruce »

pinback wrote:Perl.
Then why did you muddy the waters by asking for a solution if you weren't using Perl?

Bruce

bruce
Posts: 2544
Joined: Tue Jun 04, 2002 10:43 pm

Post by bruce »

bruce wrote:
pinback wrote:Perl.
Then why did you muddy the waters by asking for a solution if you weren't using Perl?
Also, then, for some other language, you want to look for the PCRE library. PCRE being "Perl-Compatible Regular Expressions."

Then you can, after some initialization, plug your Perl regexps into quite a number of languages.

Bruce

User avatar
pinback
Posts: 17849
Joined: Sat Apr 27, 2002 3:00 pm
Contact:

Post by pinback »

bruce wrote:
pinback wrote:Perl.
Then why did you muddy the waters by asking for a solution if you weren't using Perl?

Bruce
I'm not using Perl. I'm using PHP. Which provides Perl regex functions.
Am I a hero? I really can't say. But, yes.

User avatar
pinback
Posts: 17849
Joined: Sat Apr 27, 2002 3:00 pm
Contact:

Post by pinback »

bruce wrote: Then you can, after some initialization, plug your Perl regexps into quite a number of languages.

Bruce
Okay. Now, with that all established, can you answer my original question?
Am I a hero? I really can't say. But, yes.

k. roo
Posts: 168
Joined: Mon Sep 09, 2002 4:36 pm
Location: NJ

Post by k. roo »

pinback wrote:can you answer my original question?
You mean this one?
pinback wrote:I want to strip out all HTML tags from a string EXCEPT for a few specific ones like <i> and <b> and whatnot...
Of course.

User avatar
pinback
Posts: 17849
Joined: Sat Apr 27, 2002 3:00 pm
Contact:

Post by pinback »

None of those threads answers the question. I know how to strip out tags I don't want. I wanted to do it the other way, strip out everything BUT the ones that I DO want.

I rate all of your helpfulnesses in this thread a minus a million out of 10 so far.
Am I a hero? I really can't say. But, yes.

k. roo
Posts: 168
Joined: Mon Sep 09, 2002 4:36 pm
Location: NJ

Post by k. roo »

Code: Select all

strip_tags

&#40;PHP 3>= 3.0.8, PHP 4 , PHP 5&#41;
strip_tags -- Strip HTML and PHP tags from a string
Description
string strip_tags &#40; string str &#91;, string allowable_tags&#93; &#41;

This function tries to return a string with all HTML and PHP tags stripped from a given str. It uses the same tag stripping state machine as the fgetss&#40;&#41; function.

You can use the optional second parameter to specify tags which should not be stripped. 

Code: Select all

You can use the optional second parameter to specify tags which should not be stripped. 

Code: Select all

optional second parameter specify tags should not be stripped. 

Code: Select all

should not be stripped. 

Code: Select all

stripped. 

User avatar
pinback
Posts: 17849
Joined: Sat Apr 27, 2002 3:00 pm
Contact:

Post by pinback »

Ah. See, that's helpful now. Now you're helping.
Am I a hero? I really can't say. But, yes.

Guest

Post by Guest »

if you smell a spindle of fresh "Verbatim" CD-Rs for long enough, so that you get a little high, it smells like marzipan.

Lysander
Posts: 1693
Joined: Tue Jul 08, 2003 12:39 pm
Location: East Bay, California.

Post by Lysander »

I always thought my CDRs smelled like roses. It weirded me out.
paidforbythegivedrewbetterblowjobsfundandthelibertyconventionforastupidfreeamerica

Post Reply