Need help with RegEx string..how can I get this element?

simpleonline1234

Junior Member
Joined
Jan 26, 2010
Messages
170
Reaction score
13
I am able to get ALL id's on the page but I wanted to be able to get this particular string of html

Code:
<input autocomplete="off" type="password" tabindex="3"  size="25" name="password" id="password" value=""  onfocus="_helpOn('help__password')"

Here is my current Regex: id=.*"

This get ALL the freaking Id's on the page.

I've tried using regexr but it's not giving me any results. Any ideas on how I can get this to only show me:


id="password"

Thanks
 
you get indexed to this string for ex : size="25" name="password" and make a substring from this index to (size="25" name="password" - "value"(index)
like substring(ind1-(ind2-ind1)) the return will be id="password"
 
Can you be more specific? Do you need to match the whole <input> tag that contains the id 'password'? Also, which language are you using?
 
It doesn't matter what programming language he wants to use. Regex is platform independent.

Here you go:

Code:
id=["\S]+

You're welcome :cool:

Once you really learn how to use RegEx, your life will never be the same - seriously :)

I highly recommend rubular - it's a great resource & testing platform for regular expressions.

The above snippet in English means: take 1 or more non-whitespace characters, including the doublequote

read the description on rubular - bottom of the page and you will learn more tricks for your scraping

I don't know what you're trying to do exactly, but I think using XPath would be even easier.
 
Nice one ranktrackerpro.

I would have gone with this straight forward one
but yours is more elegant :)

The reason asking for the language are not the minor differences in regex implementations that appear, but to provide a snippet. So, if he had said C#, he 'd get something like this

Code:
bool FoundMatch = false;
try {
	FoundMatch = Regex.IsMatch(SubjectString, "id=\".+?\"");
} catch (ArgumentException ex) {
	// Syntax error in the regular expression
}
 
Back
Top