Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regex

Status
Not open for further replies.

hunt00

Technical User
Mar 6, 2005
79
0
0
US
What does the following mean in regex?

1. [:space:]
2. (/|\?)
3. [:alpha:] [:alnum:]

Thanks in advance!
 
Thanks, friend.

I am trying to enable all the different types of urls to be clickable links, including the urls wrapped in text. Got this following expression that confused me, and when testing it does break as well. I am trying to fully understand it before modify.

$text = eregi_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\0\" target=\"_blank\" title=\"\\0\">\\0</a>", $text);

1. why the alpha is inside double square bracket [[:alpha:]],instead just one [:alpha:], is it trying to make a balance with the :space: and :alnum:, but no other meannings?

2. [^<>[:space:]]+ matches for not(^) a left arrow(<) or right arrow(>) or a single space[:space:], not one or more of them should appear at that position at all. am i right?

3. the backreference refers to the match inside the round bracket, not square bracket, is it?

4. even if backreference can count with square brackets, it starts from 1, not 0, what does the 0 refer to here?

Thanks very much!
 
hunt, Are you trying to make it so that whenever someone types in a website address and submits it, it automatically gets changed to a hyperlink? Like a forum?
 
1. [:alpha:] and [:alphanum:] are called "Special Range 'metacharacters'". Treat them as a constant. The rule is that they MUST be place inside another set of brackets to give the programmer more options. eg. [[:alpha:]a-d] will search for any alpha character from a through to d.

2. Correct. The ^ symbol is called circumflex. This statement means that matches in this position should be anything BUT a space, a less than or more than symbol. I imagine the reason for this is so the statement will ignore tags in HTML. eg. <a href="....

3 and 4 - Not sure what you mean by "backreference" sorry.

You can find a ton of info on this by searching for "regular expressions", it's the same across most languages.
 
Thanks, there.

Trying to get these to be clickable

1. anything that looks like a hyperlink, Like: or or ftp://... or emails

2. a string of text which has been embedded in html tag, which is clickable text that copy and paste from somewhere else.

When reading the backreference, since it uses 1,2,3 ..to count. I am confused of the rule of counting it. Thought only count those in square brackets, and starting count number is 1.
 
3+4: \0 is a reference for the entire match. Sub-match references start with \1.

barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top