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?
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 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 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.
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,
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'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??
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.
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 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..
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.
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 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!
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
I have the following asp.net custom validator:
<asp:CustomValidator runat="server"
ClientValidationFunction="valUCRRequired" ID="valUCRRequired"
ErrorMessage="Field 7-Date/Time Between is Required"
ControlToValidate="DTE_FROM" />
Notice that the ID and ClientValidationFunction have the same value. I want to do a regular expression search where they are the same. Right now, I am just searching for all CustomValidators.
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
I have some markup that contains certain HTML image tags with the class featured. What I need is to find all those images, add an anchor tag around the image, set the href attribute of the anchor to the images src value (the image path), and lastly replace the images src value with a new value (I call a method that will return this value).
<p>Some text here <img src="/my/path/image.png" alt="image description" class="featured" />. Some more text and another image that should not be modified <img src="/my/path/image2.png" alt="image description" /></p>
Should become.
<p>Some text here <a href="/my/path/image.png"><img src="/new/path/from/method.png" alt="image description" class="featured" /></a>. Some more text and another image that should not be modified <img src="/my/path/image2.png" alt="image description" /></p>
I have about 40000 records in that table that contains plain text and within the plain text, contains that kind of tags which its only characteristic is that they are braced between [ ]
[caption id="attachment_2948" align="alignnone" width="480" caption="the caption goes here"]
How could I remove those? (replace by nothing)
I could also run a PHP program if necessary to do the cleanup.
For example, here is a string representing an expression:
var str = 'total = sum(price * qty) * 1.09875';
I want to extract variables (i.e., 'total', 'price' and 'qty' but not 'sum' since 'sum' is a function name) from this expression. What is the regexp pattern in javascript? Variable name consists of letters, digits, or the underscore, beginning with letters or the underscore.
I have to parse a big bunch of log files, which are in the following format.
SOME SQL STATEMENT/QUERY
DB20000I The SQL command completed successfully.
SOME OTHER SQL STATEMENT/QUERY
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command.
EDIT 1: The first 3 lines (including a blank line) indicate an SQL statement executed successfully, while the next three show the statement and the exception it caused. darioo's reply below, suggesting the use of grep instead of Java, works beautifully for a single line SQL statement.
EDIT 2: However, the SQL statement/query might not be a single line, necessarily. Sometimes it is a big CREATE PROCEDURE...END PROCEDURE block. Can this problem be overcome using only Unix commands too?
Now I need to parse through the entire log file and pick all occurrences of the pair of (SQL statement + error) and write them in a separate file.
Please show me how to do this!
I have this HTTP Request and I want to display only the Authorization section (base64 Value) : any help ?
This Request is stored on a variable called hreq
I have tried this :
reg = re.search(r"Authorization:\sBasic\s(.*)\r", hreq)
print reg.group()
but doesn't work
Here is the request :
HTTP Request:
Path: /dynaform/custom.js
Http-Version: HTTP/1.1
Host: 192.168.1.254
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://domain.com/userRpm/StatusRpm.htm
Authorization: Basic YWhtEWa6MDfGcmVlc3R6bGH
I want to display the value YWhtEWa6MDfGcmVlc3R6bGH
Please I need your help
thanks in advance experts
How can I parse text and find all instances of hyperlinks with a string? The hyperlink will not be in the html format of <a href="http://test.com">test</a> but just http://test.com
Secondly, I would like to then convert the original string and replace all instances of hyperlinks into clickable html hyperlinks.
I found an example in this thread:
Easiest way to convert a URL to a hyperlink in a C# string?
but was unable to reproduce it in python :(