/    Sign up×
Community /Pin to ProfileBookmark

Regular expressions Escape

I know what most of these mean but I am a bit unsure what the escape of a chracter is. It is represented by a

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@temp_user123Jul 05.2007 — It is used for two purposes -- to represent a special character sequence, or to suppress the meaning of a character sequence. For example... The following regular expression would match on the letter "t":

/t/

while the following regular expression would match on the tab character:

/t/

The following regular expression would match on any character:

/./

while the following regular expression would match only on the period character:

/./
Copy linkTweet thisAlerts:
@JavajoobauthorJul 07.2007 — So in the event of . does that have any significance
Copy linkTweet thisAlerts:
@temp_user123Jul 07.2007 — A regular expression is delimited by forward leaning slashes. So, this:

/./

Means to match on any character (except newline). That is the special significance of the period character in Regular Expressions. To prevent that special significance, and use the period character to match only on an actual period character, then the period character must be "escaped" as follows:

/./

The "escape" character is always the backward leaning slash.
Copy linkTweet thisAlerts:
@JavajoobauthorJul 07.2007 — I think it is the escape character in mind I'm just slightly unsure of what it is. I am aware that the . represents any single character
Copy linkTweet thisAlerts:
@temp_user123Jul 07.2007 — I think it is the escape character in mind I'm just slightly unsure of what it is.[/QUOTE]
I'm not sure what you mean by that -- since I've just explained it very well. Otherwise, yes, you can even escape the escape character. The following will match on the backward leaning slash character -- if that is what you desire:

//

Note, however, that is some cases you have to double-escape it:

//

This usually occurs because, internally, PHP is passing the string to another module and, thus, the escape process has to occur once again.
Copy linkTweet thisAlerts:
@JavajoobauthorJul 07.2007 — Oh it's ok I saw a sub-section which explained something to me. I appreciate your effort though
×

Success!

Help @Javajoob 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.16,
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,
)...