/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] exact match using preg_match

when I use this code, I get more then I am asking for…

[code=php]
$line = “(Q1) Some Data”;

if(preg_match(“(Q1)”,$line)) $Q1[] = $line;
[/code]

when I var_dump the Q1 array preg_match has added (Q10)… (Q11)… (Q13) and so on to the array.

What I want added is lines with an EXACT match to (Q1). What am I doing wrong?

Thanks.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 26.2009 — Parentheses are special characters in regexps, so they need to be escaped when you want literal paren characters. Also, in this case they are being used as regexp delimiters since you did not use something else.
<i>
</i>'/(Q1)/'
Copy linkTweet thisAlerts:
@robertketterauthorJan 26.2009 — thanks so much... in the future I will try to do better when it comes to delimiters.
×

Success!

Help @robertketter 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 5.14,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...