/    Sign up×
Community /Pin to ProfileBookmark

Regex help needed

I’m trying to parse the string:

[code]
Test link() filter %link(filterTest, http://www.ez-ms.com, Link Text, parent_id=x, user_id=tony, title=Link Test) and trailing text.
And this is the 2nd link() test for %link(filterTest2, http://www.ez-ms.com, 2nd Link Text, parent_id=x, user_id=tony2, title=Link Test2).
[/code]

Using this preg_match_all() call:

[code]
preg_match_all(‘;%link((.*)[^)];im’, $str, $matches);
[/code]

Without the ‘U’ modifier it returns:

[code]
matches:Array
(
[0] => Array
(
[0] => %link(filterTest, http://www.ez-ms.com, Link Text, parent_id=x, user_id=tony, title=Link Test) and trailing text.

[1] => %link(filterTest2, http://www.ez-ms.com, 2nd Link Text, parent_id=x, user_id=tony2, title=Link Test2).
)

[1] => Array
(
[0] => filterTest, http://www.ez-ms.com, Link Text, parent_id=x, user_id=tony, title=Link Test) and trailing text.
[1] => filterTest2, http://www.ez-ms.com, 2nd Link Text, parent_id=x, user_id=tony2, title=Link Test2)
)

)
[/code]

And with the ‘U’ modifier it returns:

[code]
matches:Array
(
[0] => Array
(
[0] => %link(f
[1] => %link(f
)

[1] => Array
(
[0] =>
[1] =>
)

)
[/code]

It does not seem to want to recognize the [^)] termination of the pattern space.

Can anyone help? I would like $matches to contain the arguments inside the %link(….) text so I can parse them appropriately. But I’m kind of stumped. I’ve tried changing the pattern terminator to [^)] without any luck.

Any help would be greatly appreciated.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@StevishMar 15.2009 — [^)] means "Anything accept the character ")". Have you tried just using [)] ?
Copy linkTweet thisAlerts:
@tbirnsethauthorMar 15.2009 — Yes I have (see 2nd to last line of original post). Doesn't make a difference one way or another. That's what I want as the sub-pattern terminator. I don't want the trailing ')' in the pattern match.
Copy linkTweet thisAlerts:
@StevishMar 15.2009 — In your first post you said you tried [^)]... but have you tried [)] as well?
Copy linkTweet thisAlerts:
@StevishMar 15.2009 — Just to clarify, you want it to match %link(Anything-in-here) right?
Copy linkTweet thisAlerts:
@tbirnsethauthorMar 15.2009 — That did it (outside the sub-pattern).

Thanks!
×

Success!

Help @tbirnseth spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...