Hi
Please help me with a regular expression to validate the following format
dd/mm
This is for validating a Birthday field and the year is not required.
Thanks
I need to match two cases by one reg expression and do replacement
'long.file.name.jpg' - 'long.file.name_suff.jpg'
'long.file.name_a.jpg' - 'long.file.name_suff.jpg'
I'm trying to do the following
re.sub('(\_a)?\.[^\.]*$' , '_suff.',"long.file.name.jpg")
But this is cut the extension '.jpg' and I'm getting
long.file.name_suff. instead of long.file.name_suff.jpg
I understand that this is because of [^.]*$ part, but I can't exclude it, because
I have to find last occurance of '_a' to replace or last '.'
Is there a way to replace only part of the match?
I am have completed javascript validation of a form using Regular Expressions and am now working on redundant verification server-side using PHP.
I have copied this regular expression from my jscript code that finds dollar values, and reformed it to a PHP friendly format:
/\$?((\d{1,3}(,\d{3})*)|(\d+))(\.\d{2})?$/
Specifically:
if (preg_match("/\$?((\d{1,3}(,\d{3})*)|(\d+))(\.\d{2})?$/", $_POST["cost"])){}
While the expression works great in javascript I get :
Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 1
when I run it in PHP. Anyone have a clue why this error is coming up?
I have a following string that I would like to parse into either a List or a String[].
(Test)(Testing (Value))
End result should be Test and Testing (Value)
Here are the patterns:
Red,Green (and so on...)
Red (+5.00),Green (+6.00) (and so on...)
Red (+5.00,+10.00),Green (+6.00,+20.00) (and so on...)
Red (+5.00),Green (and so on...)
Each attribute ("Red,"Green") can have 0, 1, or 2 modifiers (shown as "+5.00,+10.00", etc.).
I need to capture each of the attributes and their modifiers as a single string (i.e. "Red (+5.00,+10.00)", "Green (+6.00,+20.00)".
Help?
I'm new to Python scripting, so please forgive me in advance if the answer to this question seems inherently obvious.
I'm trying to put together a large-scale find-and-replace script using Python. I'm using code similar to the following:
findreplace = [
('term1', 'term2'),
]
inF = open(infile,'rb')
s=unicode(inF.read(),charenc)
inF.close()
for couple in findreplace:
outtext=s.replace(couple[0],couple[1])
s=outtext
outF = open(outFile,'wb')
outF.write(outtext.encode('utf-8'))
outF.close()
How would I go about having the script do a find and replace for regular expressions?
Specifically, I want it to find some information (metadata) specified at the top of a text file. Eg:
Title: This is the title
Author: This is the author
Date: This is the date
and convert it into LaTeX format. Eg:
\title{This is the title}
\author{This is the author}
\date{This is the date}
Maybe I'm tackling this the wrong way. If there's a better way than regular expressions please let me know!
Thanks!
i am extracting file names of html files using line:
filename = File.basename(input_filename, ".*")
which currently prints full file name excluding .html extension
All files are stored in the form of http^x.x.edu^1^2 all file names begin with http^ and contain edu^ what i want is to extract 2 (which changes) but it is always the second element after .edu I have attempted destructive gsub! but i m weak with regular expressions.
Hi,
I'm converting patch scripts using a commandline script - within these scripts there's the combination two lines like:
--- /dev/null
+++ filename.txt
which needs to be converted to:
--- filename.txt
+++ filename.txt
Initially I tried:
less file.diff | sed -e "s/---\/dev\null\n+++ \(.*\)/--- \1\n+++ \1/"
But I had to find out that multiline-handling is much more complex in sed :(
Any help is appreciated...
I'm parsing some big log files and have some very simple string matches for example
if(m/Some String Pattern/o){
#Do something
}
It seems simple enough but in fact most of the matches I have could be against the start of the line, but the match would be "longer" for example
if(m/^Initial static string that matches Some String Pattern/o){
#Do something
}
Obviously this is a longer regular expression and so more work to match. However I can use the start of line anchor which would allow an expression to be discarded as a failed match sooner.
It is my hunch that the latter would be more efficient. Can any one back me up/shoot me down :-)
I have a regular expression, links = re.compile('<a(.+?)href=(?:"|\')?((?:https?://|/)[^\'"]+)(?:"|\')?(.*?)>(.+?)</a>',re.I).findall(data)
to find links in some html, it is taking a long time on certain html, any optimization advice?
One that it chokes on is http://freeyourmindonline.net/Blog/
I've taken a regular expression from jQuery to detect if a browser's engine is WebKit and gets it's version number, it returns 3 values extracted from the userAgent string: webkit/….…, webkit and ….… [“….…” being the version number].
I would like the regular expression to return just 2 values: webkit and ….….
I'm rubbish at regular expressions, so please can you give an explanation of the expression with your answer.
The regular expression I'm currently working with and wish to improve is: /(webkit)[\/]([\w.]+)/.
I appreciate all your help, thanks in advance!
I want to have a function which gets a text as the input and gives back the text with URLs made to HTML links as the output.
My draft is as follows:
function autoLink($text) {
return preg_replace('/https?:\/\/[\S]+/i', '<a href="\0">\0</a>', $text);
}
But this doesn't work properly.
For the input text which contains ...
http://www.google.de/
... I get the following output:
<a href="http://www.google.de/<br">http://www.google.de/<br</a> />
Why does it include the line breaks? How could I limit it to the real URL?
Thanks in advance!
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 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...
I have some data, like this:
BUG DATE STATUS
---- ---------------------- --------
9012 18/03/2008 9:08:44 AM OPEN
9012 18/03/2008 9:10:03 AM OPEN
9012 28/03/2008 4:55:03 PM RESOLVED
9012 28/03/2008 5:25:00 PM CLOSED
9013 18/03/2008 9:12:59 AM OPEN
9013 18/03/2008 9:15:06 AM RESOLVED
9013 18/03/2008 9:16:44 AM CLOSED
9014 18/03/2008 9:17:54 AM OPEN
9014 18/03/2008 9:18:31 AM RESOLVED
9014 18/03/2008 9:19:30 AM CLOSED
9015 18/03/2008 9:22:40 AM OPEN
9015 18/03/2008 9:23:03 AM RESOLVED
9015 19/03/2008 12:27:08 PM CLOSED
9016 18/03/2008 9:24:20 AM OPEN
9016 18/03/2008 9:24:35 AM RESOLVED
9016 19/03/2008 12:28:14 PM CLOSED
9017 18/03/2008 9:25:47 AM OPEN
9017 18/03/2008 9:26:02 AM RESOLVED
9017 19/03/2008 12:30:30 PM CLOSED
Which I would like to transform into something like this:
DATE OPEN RESOLVED CLOSED
---------------------- -------- -------- --------
18/03/2008 9:08:44 AM 1 0 0
18/03/2008 9:12:59 AM 2 0 0
18/03/2008 9:15:06 AM 1 1 0
18/03/2008 9:16:44 AM 1 0 1
18/03/2008 9:17:54 AM 2 0 1
18/03/2008 9:18:31 AM 1 1 0
18/03/2008 9:19:30 AM 1 0 2
18/03/2008 9:22:40 AM 2 0 2
18/03/2008 9:23:03 AM 1 1 2
18/03/2008 9:24:20 AM 2 1 2
18/03/2008 9:24:35 AM 1 2 2
18/03/2008 9:25:47 AM 2 2 2
18/03/2008 9:26:02 AM 1 3 2
19/03/2008 12:27:08 PM 1 2 3
19/03/2008 12:28:14 PM 1 1 4
19/03/2008 12:30:30 PM 1 0 5
28/03/2008 4:55:03 PM 0 1 5
28/03/2008 5:25:00 PM 0 0 6
i.e. keeping running counts of bugs with each status.
This is easy enough to code up using cursors, but I'm wondering if any of you SQL gurus out there can help with a query to achieve this?
Ideally for mysql, but I'm curious to see anything that will work.
I have several very large XML files and I'm trying to find the lines that contain non-ASCII characters. I've tried the following:
grep -e "[\x{00FF}-\x{FFFF}]" file.xml
But this returns every line in the file, regardless of whether the line contains a character in the range specified.
Do I have the syntax wrong or am I doing something else wrong? I've also tried:
egrep "[\x{00FF}-\x{FFFF}]" file.xml
(with both single and double quotes surrounding the pattern).
Hi There,
Does anyone have a regurlar expression available which only accepts dates in the format dd/mm/yy but also has strict checking to make sure that the date is valid, including leap year support?
I am coding in vb.net and am struggling to work this one out.
Many Thanks
I need help on regular expression on the condition (4) below:
Begin with a-z
End with a-z0-9
allow 3 special characters like ._-
The characters in (3) must be followed by alphanumeric characters, and it cannot be followed by any characters in (3) themselves.
Not sure how to do this. Any help is appreciated, with the sample and some explanations.
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.
I am trying to modify a number of environmental variables containing predefined compiler flags. To do so, I tried using a bash loop that goes over all environmental variables listed with "env".
for i in $(env | grep ipo | awk 'BEGIN {FS="="} ; { print $1 } ' )
do echo $(sed -e "s/-ipo/ / ; s/-axAVX/ /" <<< $i)
done
This is not working since the loop variable $i contains just the name of the environmental variable stored as a character string. I tried searching a method to convert a string into a variable but things started becoming unnecessary complicated. The basic problem is how to properly supply the environmental variable itself to sed.
Any ideas how to properly modify my script are welcome.
Thanks,
Alex
[http://jsfiddle.net/mhmBs/][1]
I tried using the method that he uses in a jquery validator plugin.. My error container is separated from the form, it is outside the form. When I use that method to validated that the user input at least one from 3 input text boxes. It validates the field, but the other items to be validated is ignored specially the items before 3 input text boxes.
I have a list of keywords, about 25,000 of them. I would like people who add a certain < script tag on their web page to have these keywords transformed into links. What would be the best way to go and achieve this?
I have tried the simple javascript approach (an array with lots of elements and regexping/replacing each) and it obviously slows down the browser.
I could always process the content server-side if there was a way, from the client, to send the page's content to a cross-domain server script (I'm partial to PHP but it could be anything) but I don't know of any way to do this.
Any other working solution is also welcome.