Regex Find/Replace in Notepad++ advanced - regex

I'm trying to find all values and replace with following pattern :
<option value="">text1343 </option>
<option value="">text2yt4</option>
<option value="">text34ug</option>
<option value="">defffe</option>
<option value="">ewewe</option>
What do I want?
I want to copy the text between <option value=""> AND </option> then paste it between "".
like this :
<option value="text1343">text1343 </option>
How can I do a replacement?

find value
value="">(.*)?(<)
replace with
value="$1">$1<

Find: <option value="">(.*)</option>
Replace with: <option value="\1">\1</option>

Related

Scrolling and selecting a checkbox in a drop down using python webdriver

I have to select a checkbox from within a drop down. The problem is the value is not visible. I need to scroll down to reach the value.
html
<select class="select_box" tabindex="25" id="cbo_CC_CType"
name="cbo_CC_CType" multiple="multiple" multi-select="true"
autofillkey="CMDTYPE" title="COMMAND TYPE">
<option value="Authorization">Authorization</option>
<option value="Cancel">Cancel</option>
<option value="Change">Change</option>
<option value="Clear">Clear</option>
<option value="Final">Final</option>
<option value="Final1">Final</option>
<option value="Fina2">Final</option>
<option value="Fina3">Final</option>
.
.
.
.
.
.
<option value="MyCar">MyCar</option>
</select>
I tried:
chromedriver.find_element_by_xpath("//select[#id='cbo_CC_CType']/option[#value='MyCar']").click()
Can someone please help

Matching a string pattern which starts and ends with a string in imacros

Suppose This is my text
SET abc "<select name="ctl00$ContentPlaceHolder1$ddlyear" onchange="javascript:setTimeout('__doPostBack(\'ctl00$ContentPlaceHolder1$ddlyear\',\'\')', 0)" id="ctl00_ContentPlaceHolder1_ddlyear" class="page-heading" style="background-color: rgb(255, 244, 244); width: 95px; outline: 1px solid blue;"> <option selected="selected" value="Select Year">Select Year</option> <option value="2000">2000</option>
<option value="2001">2001</option>
<option value="2002">2002</option>
<option value="2003">2003</option>
<option value="2004">2004</option>
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
</select>"
And I just want to extract years from the above text, so I matched the staring string as <option value= and ending string as </option> and get the string between these two pattern
SET text EVAL("var s=\"{{abc}}\"; s.match(\"(?![<option value=])(.*)(?=</option>)\");")
But it gives the entire text again
And if I do
SET text EVAL("var s=\"{{abc}}\"; s.match(\"(?![<option value=])(.*)(?=</option>)\");s[0]")
This gives me "<"
Any suggestion where I'm going wrong?
Thanks
I think you can try a simpler way like this:
TAG XPATH="id('ctl00_ContentPlaceHolder1_ddlyear')" EXTRACT=TXTALL
SET numbers EVAL("'{{!EXTRACT}}'.replace('Select Year[OPTION]', '');")
PROMPT {{numbers}}
I can't test an imacros version, but your plain regex is wrongfully using square brackets and negative lookahead.
Here is a regex that matches what you are looking for (all digits before an </option>) :
([0-9]*)(?=</option>)
Demo here :
https://regex101.com/r/jA3Al9/2
Edit : as I said I can't test it but I guess you are looking for :
SET text EVAL("var s=\"{{abc}}\"; s.match(\"([0-9]*)(?=</option>)\");s[0]")
From #Shugar's answer added few lines to get the answer
TAG XPATH="id('ctl00_ContentPlaceHolder1_ddlyear')" EXTRACT=TXTALL
SET numbers EVAL("'{{!EXTRACT}}'.replace('Select Year[OPTION]', '');")
SET numb1 EVAL("'{{numbers}}'.replace(/[OPTION]/g,'');")
SET numb2 EVAL("'{{numb1}}'.split('[]')")
PROMPT {{numb2}}

how to ignore a word to replace using regEx?

<select class="form-control" name="work_status">
<option value="">Working With</option>
<option value="Private Company">Private Company</option>
<option value="Government/ Public sector">Government/Public Sector</option>
<option value="Government/ Public sector">Defense/Civil Services</option>
<option value="Government/ Public sector">Business/Self Employed</option>
<option value="Government/ Public sector">Not Working</option>
</select>
Here I want to remove all <option value="Ignore this">. This means I want to replace <option value=""> with "" and <option value="Private Company"> with "". I.e. I want to ignore word inside value attribute. How can I do this?
You must specify a language but for the regex part you can use this : value="(.+)"
Regex101
Anyway you dont need Regex. You can do this with javascript. Let say you use jQuery:
$('.form-control option').each(function(){
$(this).attr('value',"");
});

cfselect - how to dynamically set the selected option value w/ manual values?

If I have a select setup with with hard manual values and I want to set one of the options below as the default value based on that, how would you go about it? Like when this form is reached theres a variable that will contain 1 through 12. So if it's "6" I'd like to make "6 months" the selected value. I know you can put "selected = "selected"" directly in the option values but I don't see how to get an if statement in there. I tried doing it a few was in the cfselect and couldn't figure out anything that worked.
Thanks!
<cfselect name="months_select" id="months_select" multiple="no">
<option value="1">1 Month</option>
<option value="2">2 Months</option>
<option value="3">3 Months</option>
<option value="4">4 Months</option>
<option value="5">5 Months</option>
<option value="6">6 Months</option>
<option value="7">7 Months</option>
<option value="8">8 Months</option>
<option value="9">9 Months</option>
<option value="10">10 Months</option>
<option value="11">11 Months</option>
<option value="12">12 Months</option>
</cfselect>
You can embed the CF directly into the HTML, I've done the first one as an example.
<select name="months_select" id="months_select" multiple="no">
<option value="1" <cfif YourVariable EQ 1>selected="selected"</cfif>>1 Month</option>
<option value="2">2 Months</option>
<option value="3">3 Months</option>
<option value="4">4 Months</option>
<option value="5">5 Months</option>
<option value="6">6 Months</option>
<option value="7">7 Months</option>
<option value="8">8 Months</option>
<option value="9">9 Months</option>
<option value="10">10 Months</option>
<option value="11">11 Months</option>
<option value="12">12 Months</option>
</select>
You're better off making a loop though.
<select name="months_select" id="months_select" multiple="no">
<cfloop from="1" to="12" index="Month">
<option value="#Month#" <cfif YourVariable EQ Month>selected="selected"</cfif>>#Month# Month<cfif Month GT 1>s</cfif></option>
</cfloop>
</select>
Hope that helps.
If you're using cfselect and generating your options with a query, you can define the default value there.
<cfselect
name="months_select"
id="months_select"
multiple="no"
query="numMonths"
selected="#monthSelected#"
value="monthValue"></cfselect>

Looking to replace option value="" with the text between <option value="">this text</option>

I have this html, and I want to replace the numeric value within value="##" with the value between <option>value</option>
For example: <option value="16">Accounting</option>, I want to know the regex it'd take to automatically change it to <option value="Accounting">Accounting</option>
I plan on doing it to this entire list.
<option value="16">Accounting A.A.S.</option>
<option value="15">Accounting A.S.</option>
<option value="33">Art Studies</option>
<option value="18">Business Administration A.A.S.</option>
<option value="17">Business Administration A.S.</option>
<option value="20">Computer Network Technician</option>
<option value="21">Computer Support Specialist</option>
<option value="40">Criminal Justice A.A.S.</option>
<option value="39">Criminal Justice A.S.</option>
<option value="37">Criminal Justice: Corrections Certificate</option>
<option value="41">Criminal Justice: Cybersecurity</option>
<option value="42">Criminal Justice: Economic Crime</option>
<option value="43">Criminal Justice: Forensic Investigation</option>
<option value="34">Early Childhood</option>
<option value="22">Fashion Buying & Merchandising</option>
<option value="35">Fine Arts</option>
<option value="23">Health Services Management A.S.</option>
<option value="24">Health Services Management Technology A.A.S.</option>
<option value="92">Human Resource Management A.A.S.</option>
<option value="44">Human Services</option>
<option value="25">International Business</option>
<option value="36">Liberal Arts & Sciences: Childhood Education</option>
<option value="49">Liberal Arts & Sciences: Communication Arts</option>
<option value="50">Liberal Arts & Sciences: General Studies</option>
<option value="52">Liberal Arts & Sciences: Social Science</option>
<option value="51">Liberal Arts and Sciences: Humanities</option>
<option value="26">Marketing A.A.S.</option>
<option value="27">Medical Coder/Transcriptionist Certificate</option>
<option value="45">Music Industry</option>
<option value="28">Paralegal</option>
<option value="46">Photographic Technology</option>
<option value="47">Radio/Television Broadcasting</option>
<option value="91">Science A.S.</option>
<option value="29">Small Business Management</option>
<option value="30">Small Business Management: Certificate</option>
<option value="48">Teaching Assistant: Certificate</option>
<option value="31">Travel & Tourism: Hospitality & Events Management</option>
<option value="32">Website and E-Business Development</option>
EDIT: I want to use GREP, within textwrangler
Just remove the value attributes. <option> by default takes a value of it's content.
<option value="Accounting">Accounting</option>
is equivalent to:
<option>Accounting</option>
Edit: using sed you can do
sed -r s/' value="[0-9]+"'//g
I assume this means you want:
<option value="14">Foobar</option>
To become:
<option value="Foobar">Foobar</option>
If so, here's the Javascript. I assume the select variable contains the surrounding <select> tag DOM element, e.g. by form.nameOfselect.
for ( var option : select.options ) {
option.value = option.text;
}
Under Linux:
sed 's|<option value="[^"]*">\([^<>]*\)</option>|<option value="\1">\1</option>|g'
If your HTML is well-formed, this will do the trick:
Regex:
(?<=<option) value="\d+"
Replace with the empty string.
In HTML, option values fall back automatically to the displayed text, if no value attribute is present.
You've added that you want to perform the operation in a text editor. I wrote something assuming you'd want to use php, and I'll let it stand here because I think it's important.
Anyway, using TextWrangler (or any other text editor), replace
<option value="[^"]*">([^<]*)</option>
with
<option value="\1">\1</option>
As you're mostly active in the php tag, I assume you're asking for a solution in php. However, let me begin this answer with an advice: If you are looking for a way, state your goal, not a technology you think is suitable. regexps work, but this is far easier in simplexml:
$xml = str_replace("&", "&", $xml); // Fix errors in your XML
$doc = simplexml_load_string($xml);
foreach ($doc->xpath("//option") as $o) {
$o["value"] = "" . $o;
}
$xml = $doc->asXML();
If you insist on using a regexps, you can do so:
$xml = preg_replace(
'#<option value="[^"]*">([^<]*)</option>#',
'<option value="$1">$1</option>', $xml);
It can be made a bit more general, but it works when there are no other attributes in the option tag:
/(.*")([^"]+)(">)([^<]+)(.*)/
Then replace the captured string with this:
$1$4$3$4$5
If you're using backslash as the subgroup reference character, replace the dollar signs with backslash.
Tip: There is a great regexp tester online at http://gskinner.com/RegExr/, check it out!
I haven't tested this, but I believe this will work, using jQuery.
$('option').each(function(elm) { $(this).val($(this).text()); });