I have a lot lines contains XXXXXXXXX number format. I want change number XXXXXXXXX to XX.XXX.XXX.X
XXXXXXXXX = 9 digit random number
Anyone can help me? Thanks in advance
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).
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
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'm trying to parse various info from log files, some of which is placed within square brackets. For example:
Tue, 06 Nov 2007 10:04:11 INFO processor:receive: [someuserid], [somemessage] msgtype=[T]
What's an elegant way to grab 'someuserid' from these lines, using sed, awk, or other unix utility?
I know this may be the simplest question ever asked on Stack Overflow, but what is the regular expression for a decimal with a precision of 2?
Valid examples:
123.12
2
56754
92929292929292.12
0.21
3.1
Invalid examples:
12.1232
2.23332
e666.76
Sorry for the lame question, but for the life of me I haven't been able to find anyone that can help!
The decimal place may be option, and that integers may also be included.
i use preg_match_all and need to grab all a href="" tags in my code, but i not relly understand how to its work.
i have this reg. exp. ( /(<([\w]+)[^])(.?)(<\/\2)/ ) its take all html codes, i need only all a href tags.
i hobe i can get help :)
I am working on project where I need to find Frequency from a given text. I wrote a Regular expression that try to detect frequency, however I am stuck with how C# handle it and how exactly I use it in my software
My regular experssion is (\d*)(([,\.]?\s*((k|m)?hz)*)|(\s*((k|m)?hz)*))$
And I am trying to find value from
23,2 Hz
24,4Hz
25,0 Hzsadf
26 Hz
27Khz
28hzzhzhzhdhdwe
29
30.4Hz
31.8 Hz
4343.34.234 Khz
65SD
Further Explanation:
System needs to work for US and Belgium Culture hence, 23.2 (US) = 23,2 (Be)
I try to find a Digit, followed by either khz,mhz,hz or space or , or .
If it is , or . then it should have another Digit followed by khz, mhz, hz
Any help is appericated.
Hi guys,
I want to write a perl script that removes double tabs, line breaks and white spaces.
What I have so far is:
$txt=~s/\r//gs;
$txt=~s/ +/ /gs;
$txt=~s/\t+/\t/gs;
$txt=~s/[\t\n]*\n/\n/gs;
$txt=~s/\n+/\n/gs;
But,
1. It's not beautiful. Should be possible to do that with far less regexps.
2. It just doesn't work and I really do not know why. It leaves some double tabs, white spaces and empty lines (i.e. lines with only a tab or whitespace)
I could solve it with a while, but that is very slow and ugly.
Any suggestions?
Hi all, I'm basically trying to create my own tags - and replace them with the right HTML tags. So {B} {/B} would turn into <b> </b>
I have only got so far with this, here: http://www.nacremedia.com/text2.htm
Use the [B] button to bold stuff the current selection... it creates two bold tags and one closing for some reason.
I'm so close! But I just need a bit of direction to get the final bugs out - can anyone please help??
Also, if there is a better way of doing this altogether then I am more than welcome to new ideas.
I am using the function below to match URLs inside a given text and replace them for HTML links. The regular expression is working great, but currently I am only replacing the first match.
How I can replace all the URL? I guess I should be using the exec command, but I did not really figure how to do it.
function replaceURLWithHTMLLinks(text) {
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/i;
return text.replace(exp,"<a href='$1'>$1</a>");
}
I've started the process of moving my blog to Octopress, but unfortunately, a limitation of Jekyll doesn't allow me to use abbreviated month names for my permalinks. Therefore I'm looking to just get rid of the month and day bits altogether.
I'ved read in this article that you can use rack-rewrite to take care of the redirection, since I am using Heroku to host this.
So how would I turn:
This: example.com/journal/2012/jan/03/post-of-the-day/
Into this: example.com/journal/2012/post-of-the-day/
Extra points: If I had another rule that redirected /blog/ to /journal/, would that rule still adhere to the above one as well? So from:
This: example.com/blog/2012/jan/03/post-of-the-day/
To this: example.com/journal/2012/jan/03/post-of-the-day/
And finally to: example.com/journal/2012/post-of-the-day/
Thanks for the assistance in advance. :)
Hello,
I would like to sanitize a string in to a URL so this is what I basically need.
Everything must be removed except alphanumeric characters and spaces and dashed.
Spaces should be converter into dashes.
Eg.
This, is the URL!
must return
this-is-the-url
Thanks
I've been working on this for a few hours now and can't find any help on it. Basically, I'm trying to strip a SQL string into various parts (fields, from, where, having, groupBy, orderBy). I refuse to believe that I'm the first person to ever try to do this, so I'd like to ask for some advise from the StackOverflow community. :)
To understand what I need, assume the following SQL string:
select * from table1 inner join table2 on table1.id = table2.id
where field1 = 'sam' having table1.field3 > 0
group by table1.field4 order by table1.field5
I created a regular expression to group the parts accordingly:
select\s+(?<fields>.+)\s+from\s+(?<from>.+)\s+where\s+(?<where>.+)\s+having\s+(?<having>.+)\s+group\sby\s+(?<groupby>.+)\s+order\sby\s+(?<orderby>.+)
This gives me the following results:
fields => *
from => table1 inner join table2 on table1.id = table2.id
where => field1 = 'sam'
having => table1.field3 > 0
groupby => table1.field4
orderby => table1.field5
The problem that I'm faced with is that if any part of the SQL string is missing after the 'from' clause, the regular expression doesn't match.
To fix that, I've tried putting each optional part in it's own (...)? group but that doesn't work. It simply put all the optional parts (where, having, groupBy, and orderBy) into the 'from' group.
Any ideas?
Anyone has experience measuring glibc regexp functions?
Are there any generic tests I need to run to make such a measurements (in addition to testing the exact patterns I intend to search)?
Thanks.
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 have a php variable that comes from a form that needs tidying up. I hope you can help.
The variable contains a list of items (possibly two or three word items with a space in between words).
I want to convert it to a comma separated list with no superfluous white space. I want the divisions to fall only at commas, semi-colons or new-lines. Blank cannot be an item.
Here's a comprehensive example (with a deliberately messy input):
Variable In: "dog, cat ,car,tea pot,, ,,, ;;(++NEW LINE++)fly, cake"
Variable Out "dog,cat,car,tea pot,fly,cake"
Can anyone help?
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.
I'm migrating wiki pages from the FlexWiki engine to the FOSwiki engine using Python regular expressions to handle the differences between the two engines' markup languages.
The FlexWiki markup and the FOSwiki markup, for reference.
Most of the conversion works very well, except when I try to convert the renamed links.
Both wikis support renamed links in their markup.
For example, Flexwiki uses:
"Link To Wikipedia":[http://www.wikipedia.org/]
FOSwiki uses:
[[http://www.wikipedia.org/][Link To Wikipedia]]
both of which produce something that looks like
I'm using the regular expression
renameLink = re.compile ("\"(?P<linkName>[^\"]+)\":\[(?P<linkTarget>[^\[\]]+)\]")
to parse out the link elements from the FlexWiki markup, which after running through something like
"Link Name":[LinkTarget]
is reliably producing groups
<linkName> = Link Name
<linkTarget = LinkTarget
My issue occurs when I try to use re.sub to insert the parsed content into the FOSwiki markup.
My experience with regular expressions isn't anything to write home about, but I'm under the impression that, given the groups
<linkName> = Link Name
<linkTarget = LinkTarget
a line like
line = renameLink.sub ( "[[\g<linkTarget>][\g<linkName>]]" , line )
should produce
[[LinkTarget][Link Name]]
However, in the output to the text files I'm getting
[[LinkTarget [[Link Name]]
which breaks the renamed links.
After a little bit of fiddling I managed a workaround, where
line = renameLink.sub ( "[[\g<linkTarget>][ [\g<linkName>]]" , line )
produces
[[LinkTarget][ [[Link Name]]
which, when displayed in FOSwiki looks like
<[[Link Name> <--- Which WORKS, but isn't very pretty.
I've also tried
line = renameLink.sub ( "[[\g<linkTarget>]" + "[\g<linkName>]]" , line )
which is producing
[[linkTarget [[linkName]]
There are probably thousands of instances of these renamed links in the pages I'm trying to convert, so fixing it by hand isn't any good.
For the record I've run the script under Python 2.5.4 and Python 2.7.3, and gotten the same results.
Am I missing something really obvious with the syntax? Or is there an easy workaround?
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!
There's a question on my exercise sheet to find the complement of r = (a|b)*ab(a|b)*
I've come up with a solution, but I'm not sure if it's correct. Please help me to check, and correct my errors.
Thanks in advance.