I have a hidden code from which I am trying extract the hidden field- 320365
<fieldset class="inputs"><ol></ol></fieldset><input id="activity_id" name="activity[approval_processor][approvals_attributes][0][id]" type="hidden" value="320365" />
and I tried -
[approvals_attributes][0][id]" type="hidden" value="(.+?)"
but even the Regex Tester is not showing the number 320365. What am I doing wrong?
Almost correct, you just need to escape [ and ] as they have a special meaning in RegEx:
\[approvals_attributes\]\[0\]\[id\]" type="hidden" value="(.+?)"
Also if you know that the value is supposed to be a number, it might be better to limit it to numbers only:
\[approvals_attributes\]\[0\]\[id\]" type="hidden" value="([0-9]+)"
\[approvals_attributes\]\[0\]\[id\]" type="hidden" value="(.+?)"
or you can also use the simple eq
type="hidden" value="(.+?)"
you can also use the website - https://regex101.com/
to write any regular expressions.
Related
So I've been looking all up and down Google and I've got nothing. So can someone help?
I have my .slim file all set up and I'm trying to and a pre - code section with a line break in it...
pre
code[class="language-markup" id="copyHTML-1"]
= '<label for="name-1">Label</label>\
<input id="name-1" type="text" name="name" required>'
The output is...
<label for="name-1">Label</label>\
<input id="name-1" type="text" name="name" required>
I get the line break but I get the trailing backslash. How do I get a link break in there with no trailing backslash?
Thanks in advance.
Actually, line break in string is "\n" in Ruby, and \n must be placed in double quotes "", so you could try this:
= "<label for='name-1'>Label</label>\n
<input id='name-1' type='text' name='name' required>"
Update part:
Or you could just use slim syntax:
label[for="name-1"]
| Label
input#name-1[type="text" name="name" required]
Sounds like you might want to enable the Slim pretty-print feature, which indents nested tags on different lines.
For Rails, you could set this in an environment file., for example config/environments/development.rb:
# Indent html for pretty debugging and do not sort attributes
Slim::Engine.set_options pretty: true, sort_attrs: false
The Slim documentation has more info:
https://github.com/slim-template/slim#configuring-slim
I have used pattern I want to price equal 30 or Greater BUT not less.
Look my html code -
<input type="text" required="required" pattern="29+\.[0-9]*[1-9][0-9]*$" data-error="#Please enter price equal 30 or more" placeholder="Price" id="price" class="form-control" autocomplete="off" name="price" />
<div class="help-block with-errors"></div>
Above co I have used pattern="29+\.[0-9]*[1-9][0-9]*$" but this pattern not working. I have tried in different expression like 29*\.[0-9]*[1-9][0-9]*$, ^\d{30,}$, ^[0-9]\{30,}\$ these expressions also not working.
I am using bootstrap validator. Link = http://1000hz.github.io/bootstrap-validator/#validator-examples
Please help me.
*Edit : *
Now I am using ^[3-9]+\d*$ this is working fine. But it takes 3 or more than 3. I need 30 or more
You really should not be using regexes for this kind of task. But if you do want to, try this:
([3-9][0-9]|[0-9]{3,})
When I submit a form, Codigniter replace input names containing dots (.) with underscores (_). Here is a simple example:
<form method="post">
<input type="text" name="client.firstname" />
<input type="text" name="client.lastname" />
<input type="submit" />
</form>
$_POST contains now:
Array
(
[client_firstname] => xxxxx
[client_lastname] => yyyyy
)
So client.firstname became client_firstname with no reason?!
Do you have any idea of what is happening?
That is not CI doing this, but PHP itself – and it is a remnant of the “olden days” before there were $_POST/$_GET/etc., when external parameters where imported into the global variable scope directly; because variable names can not contain a . in PHP, because that is also the concatenation operator.
And this is documented as well, http://php.net/manual/en/language.variables.external.php:
Note:
Dots and spaces in variable names are converted to underscores. For example <input name="a.b" /> becomes $_REQUEST["a_b"].
i have a text box in my web application,Where i need to give input. I am trying to find the xpath of the text box. the following error is thrown.
Unable to locate element: {"method":"xpath","selector":"
HTML code:
<div class="input">
<input id="firstName" class="long" type="text" maxlength="50" value="" name="firstName
I want the xpath for firstName textbox.
//input[#type='text']
And this for generally targeting a text input (what I was after)
Try this one:
//input[#id='firstName']
Explanation:
// search on all levels
input for element nodes with the name of "input"
[#id='firstName'] having an attribute (#) with the name of "id" and a value of "firstName"
at least 3 simple ways to get this:
1)Driver.FindElement(By.XPath("//input[#id='firstName']"));
2)Driver.FindElement(By.Id("firstName"));
3)Driver.FindElement(By.CssSelector("#firstName"));
//*[text()[contains(.,'firstName')]]
finding by text would always work.
I am trying to match the value of the following HTML snippet:
<input name="example" type="hidden" value="matchTextHere" />
with the following:
x = response.match(/<input name="example" type="hidden" value="^.+$" \/>/)[0]
why is this not working? it doesn't match 'matchTextHere'
edit:
when i use:
x = response.match(/<input name="example" type="hidden" value="(.+)" \/>/)[0]
it matches the whole html element, and not just the value 'matchTextHere'
^ matches start of a line and $ matches end of the line. Change ^.+$ to \w+ and it will work for values that doesn't contain any symbols. Make it a parenthetical group to capture the value - (\w+)
Update: to match anything between the quotes (assuming that there aren't any quotes in the value), use [^"]+. If there are escaped quotes in the value, it is a different ballgame. .+ will work in this case, but it will be slower due to backtracking. .+ first matches upto the end of the string (because . matches even a "), then looks for a " and fails. Then it comes back one position and looks for a " and fails again - and so on until it finds the " - if there was one more attribute after value, then you will get matchTextHere" nextAttr="something as the match.
x = response.match(/<input name="example" type="hidden" value="([^"]+)" \/>/)[1]
That being said, the regex will fail if there is an extra space between any of the attribute values. Parsing html with regex is not a good idea - and if you must use regex, you can allow extra spaces using \s+
/<input\s+name="example"\s+type="hidden"\s+value="([^"]+)"\s*\/>/
Because you have a start-of-line token (^) and an end-of-line token ($) in your regular expression. I think you meant to capture the value, this might solve your problem: value="(.+?)".
Beware, though, that processing html with regular expressions is not a good idea, it can even drive you crazy. Better use an html parser instead.
You don't need the ^ and $:
x = response.match(/<input name="example" type="hidden" value=".+" \/>/)[0]
you just need to change [0] to [1]
response='<input name="example" type="hidden" value="matchTextHere" />'
puts response.match(/<input name="example" type="hidden" value="(.*?)" \/>/)[1]
matchTextHere