What will be the regular expression in javascript to match a name field,
which allows only letters, apostrophes and hyphons?
so that jhon's avat-ar or Josh is valid?
Thanks
I have a program where the user will enter a string such as
PropertyA = "abc_*" and I need to have the asterisk match any character.
In my code, I'm grabbing the property value and replacing PropertyA with the actual value. For instance, it could be abc_123. I also pull out the equality symbol into a variable.
It should be able to cover this type of criteria
PropertyB = 'cba'
PropertyC != '*-this'
valueFromHeader is the lefthand side and value is the righthand side.
if (equality.equals("=")) {
result = valueFromHeader.matches(value);
} else if (equality.equals("!=")) {
result = !valueFromHeader.matches(value);
}
EDIT:
The existing code had this type of replacement for regular expressions
final String ESC = "\\$1";
final String NON_ALPHA = "([^A-Za-z0-9@])";
final String WILD = "*";
final String WILD_RE_TEMP = "@";
final String WILD_RE = ".*";
value = value.replace(WILD, WILD_RE_TEMP);
value = value.replaceAll(NON_ALPHA,ESC);
value = value.replace(WILD_RE_TEMP, WILD_RE);
It doesn't like the underscore here...
abcSite_123 != abcSite_123 (evaluates to true)
abcSite_123$1.matches("abcSite$1123")
It doesn't like the underscore...
Scenario:
I have a text file that has pipe (as in the "|" character) delimited data.
Each field of data in the pipe delimited fields can be of variable length, so counting characters won't work (or using some sort of substring function... if that even exists in VIM).
Is it possible, using VIM / Vi to delete all data from the second pipe to the end of the line for the entire file? There are approx 150,000 lines, so doing this manually would only be appealing to a masochist...
e.g.
Change the following lines from:
1111|random sized text 12345|more random data la la la|1111|abcde
2222|random sized text abcdefghijk|la la la la|2222|defgh
3333|random sized text|more random data|33333|ijklmnop
to:
1111|random sized text 12345
2222|random sized text abcdefghijk
3333|random sized text
I'm sure this can be done somehow... I hope.
TIA
UPDATE: I should have mentioned that I'm running this on Windows XP, so I don't have access to some of the mentioned *nix commands (CUT is not recognized on Windows).
Edit: OK, I can't read, thanks to Col. Shrapnel for the help. If anyone comes here looking for the same thing to be answered...
print_r(preg_split('/([\!|\?|\.|\!\?])/', $string, null, PREG_SPLIT_DELIM_CAPTURE));
Is there any way to split a string on a set of delimiters, and retain the position and character(s) of the delimiter after the split?
For example, using delimiters of ! ? . !? turning this:
$string = 'Hello. A question? How strange! Maybe even surreal!? Who knows.';
into this
array('Hello', '.', 'A question', '?', 'How strange', '!', 'Maybe even surreal', '!?', 'Who knows', '.');
Currently I'm trying to use print_r(preg_split('/([\!|\?|\.|\!\?])/', $string)); to capture the delimiters as a subpattern, but I'm not having much luck.
what is the best way to extract last 2 characters of a string using regular expression.
For example, I want to extract state code from the following
"A_IL"
I want to extract IL as string..
please provide me C# code on how to get it..
string fullexpression = "A_IL";
string StateCode = some regular expression code....
thanks
I am an amateur in JavaScript. I saw this other question, and it made me wonder.
Can you tell me what does the below regular expression exactly mean?
split(/\|(?=\w=>)/)
Does it split the string with "|"?
Hello,
I'm running a code that read files, do some parsing but need to ignore all comments.
There are good explanations how to conduct it. like this link
$/ = undef;
$_ = <>;
s#/\*[^*]*\*+([^/*][^*]*\*+)*/|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $2 ? $2 : ""#gse;
print;
My first problem is that after run this line $/ = undef; my code doesn't work properly.
Actually, I don't know what it does. But if I could turn it back after ignoring all comments it will be helpful.
In general, What is the useful way to ignore all comments without changing the rest of the code ?
Thanks,
YoDar
Hi,
I'm using regular expression to count the total spaces in a line (first occurrence).
match(/^\s*/)[0].length;
However this reads it from the start to end, How can I read it from end to start.
Thanks
I have got a file with following format.
1234, 'US', 'IN',......
324, 'US', 'IN',......
...
...
53434, 'UK', 'XX', ....
...
...
253, 'IN', 'UP',....
253, 'IN', 'MH',....
Here I want to extract only those lines having 'IN' as 2nd keyword. i.e.
253, 'IN', 'UP',....
253, 'IN', 'MH',....
Can any one please tell me a command to grep it.
Hello
please help me
<html>
<body>
http://domainname.com/abc/xyz.zip
http://domainname2.com/abc/xyz.zip
</body>
</html>
I want replace with link and out put like
<html>
<body>
<a href="http://domainname.com/abc/xyz.zip">http://domainname.com/abc/xyz.zip</a>
<a href="http://domainname2.com/abc/xyz.zip">http://domainname2.com/abc/xyz.zip</a>
</body>
</html>
Great Thank
Take the following file...
ABCD,1234,http://example.com/mpe.exthttp://example/xyz.ext
EFGH,5678,http://example.com/wer.exthttp://example/ljn.ext
Note that "ext" is a constant file extension throughout the file.
I am looking for an expression to turn that file into something like this...
ABCD,1234,http://example.com/mpe.ext
ABCD,1234,http://example/xyz.ext
EFGH,5678,http://example.com/wer.ext
EFGH,5678,http://example/ljn.ext
In a nutshell I need to capture everything up to the urls. Then I need to capture each URL and put them on their own line with the leading capture.
I am working with sed to do this and I cannot figure out how to make it work correctly. Any ideas?
I want to validate login name with special characters !@#S%^*()+_-?/<:"';. space using regular expression in ruby on rails. These special characters should not be acceptable. What is the code for that?
Thanks,
Pallavi
I want the validator for password text input.
At least one Upper case letter
At least one numeric character
At least one special character such as @, #, $, etc.
should be there in password how can i give it in action script or mxml.please help me.
Thanks.
I need a regular expression for some arguments that must match on a string.
here it is...
The string exists out of minimum 8 en maximum 20 characters.
These characters of this string may be characters of the alfabet or special chars
--With other words..all charachters except from the whitespaces
In the complete string there must be atleast 1 number.
The string cannot start with a number or an underscore
The last 2 characters of the string must be identical, But it doenst matter if those last --identical characters are capital or non-capital (case insensitive)
Must match all :
+234567899
a_1de*Gg
xy1Me*__
!41deF_hij2lMnopq3ss
C234567890123$^67800
*5555555
sDF564zer""
!!!!!!!!!4!!!!!!!!!!
abcdefghijklmnopq9ss
May not match :
Cannot be less then 8 or more then 20 chars:
a_1+Eff
B41def_hIJ2lmnopq3stt
Cannot contain a whitespace:
A_4 e*gg
b41def_Hij2l nopq3ss
Cannot start with a number or an underscore:
__1+Eff
841DEf_hij2lmnopq3stt
cannot end on 2 diffrent characters:
a_1+eFg
b41DEf_hij2lmnopq3st
Cannot be without a number in the string:
abCDefghijklmnopqrss
abcdef+++dF
!!!!!!!!!!!!!!!!!!!!
------------------------------------------------------
This is what I have so far...But I'm really breaking my head on this...
If you Don't know the answer completely it's not a problem...
I just want to get in the right direction
([^0-9_])(?=.*\d)(\S{8,20})(?i:[\S])\1
Hi
below is something I am trying to do with JavaScript.
If I have string like
str = "how are you? hope you are doing good" ;
now I want to split it with ? but I dont want to lose the "?". Instead I want to break the string just after the question mark such a way that question mark is with the first segment that we have
after splitting str what should I get is
["how are you?","hope you are doing good"]
I am not sure if it can be done with Javascript split() function ,please help.
I'm working on 2 cases:
assume I have those var:
a = "hello"
b = "hello-SP"
b = "not_hello"
1 - Any partial matches
I want to accept any string that has the var a inside, so b and c would match.
2 - Patterned match
I want to match a string that has a inside, followed by '-', so b would match, c does not.
I am having problem, because I always used the syntax /expression/ to define Regexp, so how dinamicaly define an RegExp on Ruby??
Hi. When I want to get the title of a remote webiste, I use this script:
function get_remotetitle($urlpage)
{
$file = @fopen(($urlpage),"r");
$text = fread($file,16384);
if (preg_match('/<title>(.*?)<\/title>/is',$text,$found)) {
$title = $found[1];
} else {
$title = 'Title N/A';
}
return $title;
}
But when I parase a webiste title with accents, I get "?". But if I look in PHPMyAdmin, I see the accents correctly. What's happening?
Hi,
$dbLink = mysql_connect('localhost', 'root', 't');
mysql_select_db('pc_spec', $dbLink);
$html = file_get_contents('http://localhost/pc_spec/scrape.php?q=amd+955');
echo $html;
$html = strip_tags($html);
$price = ereg("\$.{6}", $html);
$html = mysql_real_escape_string($html);
$price = mysql_real_escape_string($price);
$insert = mysql_query("INSERT INTO parts(part, price) values('$html','$price')") or var_dump(mysql_error());
How can I get $price to match $.{6} and insert this value (eg. $111.11) into a database and remove it from $html? Do I need to use explode?
Thanks
Given a string that ends in a whitespace character return true.
I'm sure I should be able to do this with regular expressions but I'm not having any luck. MSDN reference for regular expressions tells me that \s should match on a whitespace, but I can't figure the rest out.
In my web app I've got a form field where the user can enter an URL. I'm already doing some preliminary client-side validation and I was wondering if I could use a regexp to validate if the entered string is a valid URL. So, two questions:
Is it safe to do this with a regexp? A URL is a complex beast, and just like you shouldn't use a regexp for parsing HTML, I'm worried that it might be unsuitable for a URL as well.
If it can be done, what would be a good regexp for the task? (I know that Google turns up countless regexps, but I'm worried about their quality).
My goal is to prevent a situation where the URL appears in the web page and is unusable by the browser.
Would you hire a developer who doesn't know how to use regular expressions?
That's about it, please state your reasons for or against, and feel free to give different answers for different situations. Just try to break up your answers if you can.
I have a string. That string is a html code and it serves as a teaser for the blog posts I am creating. The whole html code (teaser) is stored in a field in the database.
My goal: I'd like to make that when a user (facebook like social button) likes certain blog post, right data is displayed on his news feeds. In order to do that I need to extract from the teaser in the first occurrence of an image an image path inside src="i-m-a-g-e--p-a-t-h". I succeeded when a user puts only one image in teaser, but if he accidentally puts two images or more the whole thing craches.
Furthermore, for description field I need to extract text inside the first occurrence inside <p> tag. The problem is also that a user can put an image inside the first tag.
I would very much appreciate if an expert could help me resolve this what's been bugging me for days.
Text string with a regular expression for extracting src can be found here: http://rubular.com/r/gajzivoBSf
Thanks!
Hi
what will be the regular expression to extract challenge var value
i am interested in this vlaue
03AHJ_Vut9LJLOJuCsjF9PbSSMncTyUe7Y4dHX11eRLae3LGfDZ0hSfDR7jZq2ZrKJxyC-LRSSppv72oHKaQMsd-EnoVNL6p7liTh7siN26zzTA_E2rcC_JQ15613Azz4qm8HjPtAyksUdc7QZydszwolk92hBPrAAig
this value changes every time we refresh it so the expression has to be generic enough to pick up what ever is the value
var RecaptchaState = {
site : '6LeKCL8SAAAAADV5Dr-lfY2eOEV8rubeN25BAKp2',
challenge : '03AHJ_Vut9LJLOJuCsjF9PbSSMncTyUe7Y4dHX11eRLae3LGfDZ0hSfDR7jZq2ZrKJxyC-LRSSppv72oHKaQMsd-EnoVNL6p7liTh7siN26zzTA_E2rcC_JQ15613Azz4qm8HjPtAyksUdc7QZydszwolk92hBPrAAig',
is_incorrect : false,
programming_error : '',
error_message : '',
server : 'http://www.google.com/recaptcha/api/',
timeout : 18000};
any help will be appreciated, or any method to extract this value in any server side lang
I have a list of phone numbers that start with the below numbers and in different formats...i need to grab the numbers that start only with the below numbers/format using php......
020 8
07974
+44 (0) 20
+44 0
440203
any help will be appreciated..