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 a perl code:
my $s = "The+quick+brown+fox+jumps+over+the+lazy+dog+that+is+my+dog";
what I want is to replace every + with space and dog with cat
i have this regular expression
$s =~ s/+(.*)dog/ ${1}cat/g;
But it only match first occurrence of + and last dog.
Please help
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.
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 "|"?
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).
What will be proper regular expression for git repositories?
example link:
[email protected]:someone/someproject.git
so it will be like
server can be url or ip
Project can contain some other characters than alphanumeric like '-'
I'm not sure what is the role of '/'
any suggestions?
I trying to parse this string:
$right = '34601)S(1,6)[2] - 34601)(11)[2] + 34601)(3)[2,4]';
with following regexp:
const word = '(\d{3}\d{2}\)S{0,1}\([^\)]*\)S{0,1}\[[^\]]*\])';
preg_match('/'.word.'{1}(?:\s{1}([+-]{1})\s{1}'.word.'){0,}/', $right, $matches);
print_r($matches);
i want to return array like this:
Array
(
[0] => 34601)S(1,6)[2] - 34601)(11)[2] + 34601)(3)[2,4]
[1] => 34601)S(1,6)[2]
[2] => -
[3] => 34601)(11)[2]
[4] => +
[5] => 34601)(3)[2,4]
)
but i return only following:
Array
(
[0] => 34601)S(1,6)[2] - 34601)(11)[2] + 34601)(3)[2,4]
[1] => 34601)S(1,6)[2]
[2] => +
[3] => 34601)(3)[2,4]
)
i think, its becouse of [^)]* or [^]]* in the word,
but how i should correct regexp for matching this in another way?
i tryied to specify it:
\d+(?:[,#]\d+){0,}
so word become
const word = '(\d{3}\d{2}\)S{0,1}\(\d+(?:[,#]\d+){0,}\)S{0,1}\[\d+(?:[,#]\d+){0,}\])';
but it gives nothing
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
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?
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 am looking to split up multiple lines of text to single them out, for example:
Url/Host:ftp://server.com/1
Login:Admin1
Password:Password1
Url/Host:ftp://server.com/2
Login:Admin2
Password:Password2
Url/Host:ftp://server.com/3
Login:Admin3
Password:Password3
How can I split each section into a different textbox, so that section one would be put into TextBox1.Text on its own:
Url/Host:ftp://server.com/1
Login:Admin1
Password:Password1
Thanks in advance :)!
Is there a way to obtain patterns in one file (a list of patterns) from another file using ack as the -f option in grep? I see there is an -f option in ack but it's different with the -f in grep.
Perhaps an example will give you a better idea. Suppose I have file1:
file1:
a
c
e
And file2:
file2:
a 1
b 2
c 3
d 4
e 5
And I want to obtain all the patterns in file1 from file2 to give:
a 1
c 3
e 5
Can ack do this? Otherwise, is there a better way to handle the job (such like awk or using hash) because I have millions of records in both files and really need an efficient way to complete? Thanks!
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'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??
I have a text file like below
iv_destination_code_10
TAP310_mapping_RATERUSG_iv_destination_code_10
RATERUSG.iv_destination_code_10 = WORK.maf_feature_info[53,6]
iv_destination_code_2
TAP310_mapping_RATERUSG_iv_destination_code_2
RATERUSG.iv_destination_code_2 = WORK.maf_feature_info[1,6]
iv_destination_code_3
TAP310_mapping_RATERUSG_iv_destination_code_3
RATERUSG.iv_destination_code_3 = WORK.maf_feature_info[7,6]
iv_destination_code_4
TAP310_mapping_RATERUSG_iv_destination_code_4
RATERUSG.iv_destination_code_4 = WORK.maf_feature_info[13,6]
iv_destination_code_5
TAP310_mapping_RATERUSG_iv_destination_code_5
RATERUSG.iv_destination_code_5 = WORK.maf_feature_info[19,6]
iv_destination_code_6
TAP310_mapping_RATERUSG_iv_destination_code_6
RATERUSG.iv_destination_code_6 = WORK.maf_feature_info[29,6]
iv_destination_code_7
TAP310_mapping_RATERUSG_iv_destination_code_7
RATERUSG.iv_destination_code_7 = WORK.maf_feature_info[35,6]
iv_destination_code_8
TAP310_mapping_RATERUSG_iv_destination_code_8
RATERUSG.iv_destination_code_8 = WORK.maf_feature_info[41,6]
iv_destination_code_9
TAP310_mapping_RATERUSG_iv_destination_code_9
RATERUSG.iv_destination_code_9 = WORK.maf_feature_info[47,6]
combination of three lines form a unit:
iv_destination_code_9
TAP310_mapping_RATERUSG_iv_destination_code_9
RATERUSG.iv_destination_code_9 = WORK.maf_feature_info[47,6]
is one unit.
iv_destination_code_9
9 indicates the number by which i have to sort
10
9
8....
i need a shell script/awk which will sort the units in a descending order.
how is it possible?
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 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 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 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
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
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 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..