I have read the other posts, e.g., http://stackoverflow.com/questions/1830886/vim-executing-a-list-of-editor-commands and others. The answer isn't clear to me for my case. I have some editor commands that I generated from an SQL query. It uses :s/foo/bar to change country codes (from FIPS to a non-standard code set). Here's a sample of the file:
:s/CB/CAMBO
:s/CQ/NMARI
:s/KV/KOSOV
:s/PP/PAPUA
...
I have saved that in a file called fipsToNonStd.vim (unsure about the correct extension). I want to run those commands one after another. What's the easiest way to do so?
Thanks a bunch! SO Rocks!
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 am very very very new to C# and ASP.NET development.
What I'd like to do is a find-and-replace for certain words appearing in the body text of a web page. Every time a certain word appears in the body text, I'd like to convert that word into a hyperlink that links to another page on our site.
I have no idea where to even start with this. I've found code for doing find-and-replace in C#, but I haven't found any help for just reading through a document, finding certain strings, and changing them into different strings.
Hi, i don't know about regular expressions, I asked here for one that:
gets either anything up to the first parenthesis/colon or the first word inside the first parenthesis. This was the answer:
preg_match('/(?:^[^(:]+|(?<=^\\()[^\\s)]+)/', $var, $match);
I need an improvement, I need to get either anything up to the first parenthesis/colon/quotation marks or the first word inside the first parenthesis.
So if I have something like:
$var = 'story "The Town in Hell"s Backyard'; // I get this: $match = 'story';
$var = "screenplay (based on)"; // I get this: $match = 'screenplay';
$var = "(play)"; // I get this: $match = 'play';
$var = "original screen"; // I get this: $match = 'original screen';
Thanks!
I am trying to parse a file generated by LGA Tracon that lists the position data for aircraft over a given time frame. The data of interest starts with TRACKING DATA and ends with SST and there are thousands of entries per file. The system generating the file, Common ARTS, is very rigid in its formatting and we can expect the column spacing to be consistent. Any help would be greatly appreciated.
Thanks,
Here is an image to preserve the exact formatting
Here is a reduced text file.
link text
I have a string in my code that I receive that contains some html tags. It is not part of the HTML page being displayed so I cannot grab the html tag contents using the DOM (i.e. document.getElementById('tag id').firstChild.data);
So, for example within the string of text would appear a tag like this:
12
My question is how would I use a regular expression to access the '12' numeric digit in this example? This quantity could be any number of digits (i.e. it is not always a double digit).
I have tried some regular expressions, but always end up getting the full span tag returned along with the contents. I only want the '12' in the example above, not the surrounding tag. The id of the tags will always be 'myQty' in the string of text I receive.
Thanks in advance for any help!
I'm using GNU Make 3.81, and I have the following rule in my Makefile:
jslint :
java org.mozilla.javascript.tools.shell.Main jslint.js mango.js \
| sed 's/Lint at line \([0-9]\+\) character \([0-9]\+\)/mango.js:\1:\2/'
This works fine if I enter it directly on the command line, but the regular expression does not match if I run it with "make jslint". However, it works if I replace \+ with \{1,\} in the Makefile:
jslint :
java org.mozilla.javascript.tools.shell.Main jslint.js mango.js \
| sed 's/Lint at line \([0-9]\{1,\}\) character \([0-9]\{1,\}\)/mango.js:\1:\2/'
Is there some special meaning to \+ in Makefiles, or is this a bug?
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.
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 all,
I am doing some self learning about Patern Matching in Javascript.
I got a simple input text field in a HTML web page,
and I have done some Javascript to capture the string and check if there
are any strange characters other than numbers and characters in the string.
But I am not sure if it is correct.
Only numbers, characters or a mixture of numbers and characters are allowed.
var pattern = /^[a-z]+|[A-Z]+|[0-9]+$/;
And I have another question about Pattern Matching in Javascript,
what does the percentage symbol mean in Pattern matching.
For example:
var pattern = '/[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/';
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
I'm using the Markdown library for PHP by Michel Fortin. I started noticing that it formats the text in tags with markdown rules, like so:
http://foo.com/My_Url_With_Underscores
essentially becomes:
<a href="...">http://foo.com/My<em>Url</em>With_Underscores</a>
How do I disable that behavior or otherwise prevent the library from doing that?
I need to change some characters that are not ASCII to '_'.
For example,
Tannh‰user - Tann_huser
If I use regular expression with Python, how can I do this?
Is there better way to do this not using RE?
When the regular expression has a capturing group followed by "*" or "?", there is no value captured. Instead if you use "+" for the same string, you can see the capture.
I need to be able to capture the same value using "?"
>>> str1='This string has 29 characters'
>>> re.search(r'(\d+)*', str1).group(0)
''
>>> re.search(r'(\d+)*', str1).group(1)
>>>
>>> re.search(r'(\d+)+', str1).group(0)
'29'
>>> re.search(r'(\d+)+', str1).group(1)
'29'
More specific question is added below for clarity:
I have str1 and str2 below, and I want to use just one regexp which will match both. In case of str1, I also want to be able to capture the number of QSFP ports
>>> str1='''4 48 48-port and 6 QSFP 10GigE Linecard 7548S-LC'''
>>> str2='''4 48 48-port 10GigE Linecard 7548S-LC'''
>>>
When I do not use a metacharacter, the capture works:
>>> re.search(r'^4\s+48\s+.*(?:(\d+)\s+QSFP).*-LC', str1, re.I|re.M).group(1)
'6'
>>>
It works even when I use the "+" to indicate one occurrence:
>>> re.search(r'^4\s+48\s+.*(?:(\d+)\s+QSFP)+.*-LC', str1, re.I|re.M).group(1)
'6'
>>>
But when I use "?" to match for 0 or 1 occurrence, the capture fails even for str1:
>>> re.search(r'^4\s+48\s+.*(?:(\d+)\s+QSFP)?.*-LC', str1, re.I|re.M).group(1)
>>>
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 want to break a Python string into its characters.
sequenceOfAlphabets = list( string.uppercase )
works.
However, why does not
sequenceOfAlphabets = re.split( '.', string.uppercase )
work?
All I get are empty, albeit expected count of elements
I know charwise positions of matches like 1 3 7 8. I need to know their corresponding line number.
Example: file.txt
Match: X
Mathes: 1 3 7 8.
Want: 1 2 4 4
$ cat file.txt
X2
X
4
56XX
[Added: does not notice many linewise matches, there is probably easier way to do it with stacks]
$ java testt
1
2
4
$ cat testt.java
import java.io.*;
import java.util.*;
public class testt {
public static String data ="X2\nX\n4\n56XX";
public static String[] ar = data.split("\n");
public static void main(String[] args){
HashSet<Integer> hs = new HashSet<Integer>();
Integer numb = 1;
for(String s : ar){
if(s.contains("X")){
hs.add(numb);
numb++;
}else{
numb++;
}
}
for (Integer i : hs){
System.out.println(i);
}
}
}
Ok so i'm executing the following line of code in javascript
RegExp('(http:\/\/t.co\/)[a-zA-Z0-9\-\.]{8}').exec(tcont);
where tcont is equal to some string like 'Test tweet to http://t.co/GXmaUyNL' (the content of a tweet obtained by jquery).
However it is returning, in the case above for example, 'http://t.co/GXmaUyNL,http://t.co/'.
This is frustracting because I want the url without the bit on the end - after and including the comma.
Any ideas why this is appearing? Thanks
I'm looking for a regular expression to isolate an html tag. This includes the TAG the ATTRIBUTES and the CONTNET inside.
Let's say I have this:
<html>
<body>
aajsdfkjaskd
<TAGNAME name="bla" context="non">hfdfhdj </TAGNAME>
</body>
</html>
I need a regular expression that would return:
<TAGNAME name="bla" context="non">hfdfhdj </TAGNAME>
Thank,
Joe
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.
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.
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