Help matching a pattern.

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

Moderator: General Moderators

Post Reply
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Help matching a pattern.

Post by Pyrite »

Can someone help me for a regex that would find:

Code: Select all

<pre>some text</pre>
But assuming the text between the two tags could be anything, and span multiple lines.
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post by stereofrog »

What did you try and what exactly didn't work?
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

Hmm, I don't have my original script, it's at home. But i think it was something like.

Code: Select all

$pattern = '!<pre>(.*)</pre>!mi';
I'll post more when I get home from work.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Switch "m" to "s" and add "U" ;)
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

One of the things I'm trying to fix is I'm doing a job for a company whose phpdoc is incorrect in tons of files. Check this out:

Code: Select all

//*********************************************
/**
 * function setPrimaryKeyValue
 * <pre>
 * Sets the value of the primary key field.
 * </pre>
 * @param $primaryKey [STRING] new primary key value
 * @return [void]
 */
You'll notice the first line either has to end with a period or have a blank docblock line after it (which it has neither), so since the short description can be up to 3 lines long, it grabs the first 3 lines including the first pre tag and puts that as the short description, and then phpdoc gripes about not closing the pre tag. I need to make some kind of pattern that can find this type of goof up and fix it by putting a blank docblock line after the first line of text.

Any suggestions?
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

Aside from that, you might also notice that their @param is used incorrectly. They use it like:

Code: Select all

@param $parameterName [paramType] Description
But I'm pretty sure it is supposed to be:

Code: Select all

@param paramTypeWithoutBrackets $parameterName Description
Does phpdoc really care or does anyone know. How are you supposed to use valid php data types when php doesn't use data types. lol
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

feyd wrote:Switch "m" to "s" and add "U" ;)
Thanks feyd, that did the trick! Cheers.

Now I just have to figure out how to make this switcharoo work.
Post Reply