0

I have a input type="text" field I want to fetch the value attribute out of it but the condition is the id of input tag must contains "PlaceHolderSearchArea" this term

the html of input field is like this

<input name="ctl00$PlaceHolderSearchArea$SearchBox$S633C1122_InputKeydummywords" type="text" value="something something" maxlength="200" id="ctl00_PlaceHolderSearchArea_SearchBox_S622C1022_InputKeywords" accesskey="S" title="something..." class="ms-sbplain" alt="something..." onkeypress="javascript: return S633C1122_OSBEK(event);" onfocus="if (document.getElementById('ctl00_PlaceHolderSearchArea_SearchBox_ctl04').value =='0') {this.value=''; if (this.className == 's4-searchbox-QueryPrompt') this.className = ''; else this.className = this.className.replace(' s4-searchbox-QueryPrompt',''); document.getElementById('ctl00_PlaceHolderSearchArea_SearchBox_ctl04').value=1;}" onblur="if (this.value =='') {this.value='Enter Search Term'; if (this.className.indexOf('s4-searchbox-QueryPrompt') == -1) this.className += this.className?' s4-searchbox-QueryPrompt':'s4-searchbox-QueryPrompt'; document.getElementById('ctl00_PlaceHolderSearchArea_SearchBox_ctl04').value = '0'} else {document.getElementById('ctl00_PlaceHolderSearchArea_SearchBox_ctl04').value='1';}" style="width:170px;" />

can someone suggest a regex to achieve this

Mac
  • 6,991
  • 8
  • 35
  • 67

2 Answers2

0

Try this - but I'm not massively confident it's perfect.

/(?:id=('|")[^\1]*PlaceHolderSearchArea[^\1]*\1[^>]*)value=('|")(.*?\2)/

Only thing is it assumes the ID attribute comes before value.

Works in this example (JS)

'<input name="ctl00$PlaceHolderSearchArea$SearchBox$S633C1122_InputKeydummywords" type="text" value="something something" maxlength="200" id="ctl00_PlaceHolderSearchArea_SearchBox_S622C1022_InputKeywords" accesskey="S" value="hello" title="something..." class="ms-sbplain" alt="something..." style="width:170px;" />'.match(/(?:id=('|")[^\1]*PlaceHolderSearchArea[^\1]*\1[^>]*)value=('|")(.*?\2)/);
Mitya
  • 33,629
  • 9
  • 60
  • 107
0
@"(<input)([^>]*)(type=\"")(text)(\"")([^>]*)(value=\"")([^\""]*)(\"")([^>]*)(id=\"")(\w*PlaceHolderSearchArea\w*)(\"")([^>]*)(/>)"

The above expression did the trick for me

Mac
  • 6,991
  • 8
  • 35
  • 67