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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I suck at RegEx 1

Status
Not open for further replies.

SPYDERIX

Technical User
Jan 11, 2002
1,899
0
0
CA
Can someone please help me.

I have an html tag:
Code:
<div id="myid" class="myclass " data="QAZwsxedc12345.pdf" data-height="100" data-width="100">

I'm trying to use regex to find this div which has a unique id and I want to strip out the data portion that has the PDF file name.

I was trying
Code:
<div\sid=\"myid\"\sclass=\"myclass\s\"\sdata=\"[a-zA-Z0-9].pdf\"

I'm not getting anywhere and I'm useless at regex. I simply want to find a <div match id="myid" then get the value contents of data=""

Thanks

NATE
 
Hi

Like this ?
Code:
php > var_dump(preg_match('/<div\sid=\"myid\"\sclass=\"myclass\s\"\sdata=\"([a-zA-Z0-9][highlight]+[/highlight][highlight pink]\[/highlight].pdf)\"/', '<div id="myid" class="myclass " data="QAZwsxedc12345.pdf" data-height="100" data-width="100">', $match), $match);
int(1)
array(2) {
  [0] =>
  string(57) "<div id="myid" class="myclass " data="QAZwsxedc12345.pdf""
  [1] =>
  string(18) "QAZwsxedc12345.pdf"
}
[ul]
[li]There are more than 1 alphanumeric characters before the ".pdf" extension, so use a [highlight]+[/highlight] quantifier[/li]
[li]The dot ( . ) is a metacharacter so escape it with backslash ( [highlight pink]\[/highlight] )[/li]
[/ul]


Feherke.
feherke.github.io
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top