0

Okay, a little context. I want to modify some crappy HTML on a page that I use a lot. I'm doing this via my content_script "js", as defined in the manifest.json file of the chrome extension. The primary method I've been using is this sort of ugly thing:

var str1 = 'something already on the page'; var str2 = 'something already on the page, plus some extra stuff'; document.body.innerHTML = document.body.innerHTML.replace(str,st2); 

I'm mostly trying to re-order form objects, and expand them a little to show more information, and filter/condense them to be less superfluous. I'd appreciate any pointer as to a better way to do this.

Anyway... here's my specific problem.

I want to retrieve pistol (or any string) from the following:

<form action="map.cgi?use-o" method="post" class="a"><input type="submit" value="pistol" class="m"\></form> 

I tried every variation of the following:

str.exec(/value="([^]+)" class/); 

and I'm either getting null or junk strings that I don't want. Ideas?

Thanks!

2
  • Why are you using regex, why not use html dom functions Commented Apr 13, 2015 at 1:37
  • You are better off to use JavaScript code for it Commented Apr 13, 2015 at 1:37

1 Answer 1

1

If you insist on regex, then use below one:

(?:value=")([^"]+) 

Here is DEMO

Using JavaScript it will look like:

var value = document.querySelectorAll("input[type=submit]")[0].value; 
Sign up to request clarification or add additional context in comments.

2 Comments

does this just look for the string "input[type=submit]" or is it more intelligent than that somehow? also, are you missing an open parenthesis?
It takes the first input submit on the page. I can not see your whole page, but it will work for provided code.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.