How to extract the number in the string "Task(12345)" with Regular Expression and Powershell? I tried the following, but no chance.
$file = gc myfile.txt
$matches = ([regex]"Task\(\d{1,5}\)").matches($file)
# Get a list of numbers
Could someone please help me to find the correct regular expression?
Thanks,
Martin
...
From the Pattern javadocs:
Greedy quantifiers:
X? X, once or not at all
X* X, zero or more times
X+ X, one or more times
X{n} X, exactly n times
X{n,} X, at least n times
X{n,m} X, at least n but not more than m times
Reluctant quantifiers:
X?? X, once or not at all
X*? X, zero or more times
X+...
I know precisely zilch about regular expressions and figured this was as good an opportunity as any to learn at least the most basic of basics.
How do I do this case-insensitive string replacement in C# using a regular expression?
myString.Replace("/kg", "").Replace("/KG", "");
(Note that the '/' is a literal.)
...
I've been playing around with GEdit's syntax highlighting. I love the way that Visual Studio highlight's user created types. I would like to do this for my user created types in C/C++ (eg. typedef's/classes). For example (in C):
typedef struct Node *pNode;
And an example in C++:
class BigNumber
{
// Class stuff here.
};
See t...
With the following regex, it is not matching -lp[number]
public static Regex lPageID = new Regex(@"\-lp\d+\.", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public static int GetPageIDFromPath(string path)
{
return GetIDFromPath(lPageID, path);
}
example path that is sent to my function:
/domain/Some-Landing-Page-Meta-Title-...
I have GPS information presented in the form:
36°57'9" N 110°4'21" W
I can use the javascript functions of Chris Veness to convert degrees, minutes and seconds to numeric degrees, but first need to parse the GPS info into the individual latitude and longitude strings (with NSEW suffixes). I have read related posts on stackoverflow, but...
Hello guys. am new to regular expression.
I have comma seperated list of regular expressions like: .{8},[0-9],[^0-9A-Za-z ],[A-Z],[a-z]. I have done a split on the comma. Now am trying to match of this regex against a generated password. The problem is that Pattern.compile does not like square brackets that is not escaped. Can some plea...
I need to separate out a bunch of image urls from a document in which the images are associated with names like this:
bellpepper = "http://images.com/bellpepper.jpg"
cabbage = "http://images.com/cabbage.jpg"
lettuce = "http://images.com/lettuce.jpg"
pumpkin = "http://images.com/pumpkin.jpg"
I assume I can detect the start of a link wi...
Let's say I have a regular expression that works correctly to find all of the URLs in a text file:
(http://)([a-zA-Z0-9\/\.])*
If what I want is not the URLs but the inverse - all other text except the URLs - is there an easy modification to make to get this?
...
Sorry, this is probably really easy. But if you have a delimiter character on each line and you want to find all of the text before the delimiter on each line, what regular expression would do that? I don't know if the delimiter matters but the delimiter I have is the % character.
...
I am using the following regex to match a URL:
$search = "/([\S]+\.(MUSEUM|TRAVEL|AERO|ARPA|ASIA|COOP|INFO|NAME|BIZ|CAT|COM|INT|JOBS|NET|ORG|PRO|TEL|AC|AD|AE|AF|AG|AI|AL|AM|AN|AO|AQ|AR|AS|AT|AU|au|AW|AX|AZ|BA|BB|BD|BE|BF|BG|BH|BI|BJ|BL|BM|BN|BO|BR|BS|BT|BV|BW|BY|BZ|CA|CC|CD|CF|CG|CH|CI|CK|CL|CM|CN|CO|CR|CU|CV|CX|CY|CZ|DE|DJ|DK|DM|DO|DZ...
Hello,
today my objective is to retrieve all PHP class names associated with
their namespace names but I got stuck. Here is an example of what I have:
$content =<<<END
<?php
namespace test;
class a { }
class b { }
namespace foo;
class bar { }
?>
END;
preg_match_all('~^\s*((?:namespace)\s+(\w+);)?\s*(?:abstract\s+|final\s+)?(?...
I am using a simple regular expression (in C#) to find a whole word within a block of text.
The word may appear at the beginning, end or in the middle of a the text or sentence with in the text.
The expression I have been using \bword\b has been working fine however if the word included a special character (that has been escaped) it n...
I'm trying build a regex that will replace any characters not of the format:
any number of digits, then optional (single decimal point, any number of digits)
i.e.
123 // 123
123.123 // 123.123
123.123.123a // 123.123123
123a.123 // 123.123
I am using ereg_replace in php and the closest to a working regex i h...
Is there a way to optimize the following PHP code so that I can only use preg_replace and not preg_replace+substr?
$type = substr( preg_replace('/([^a-z])/', '$2', strtolower($_GET["type"])) , 0, 3);
...
I'd like to create a regex that will match an opening <a> tag containing an href attribute only:
<a href="doesntmatter.com">
It should match the above, but not match when other attributes are added:
<a href="doesntmatter.com" onmouseover="alert('Do something evil with Javascript')">
Normally that would be pretty easy, but the HTML ...
I have found the following expression which is intended to modify the id of a cloned html element e.g. change contactDetails[0] to contactDetails[1]:
var nel = 1;
var s = $(this).attr(attribute);
s.replace(/([^\[]+)\[0\]/, "$1["+nel+"]");
$(this).attr(attribute, s);
I am not terribly familiar with regex, but have tried to ...
I need to separate out a bunch of image urls from a document in which the images are associated with names like this:
bellpepper = "http://images.com/bellpepper.jpg"
cabbage = "http://images.com/cabbage.jpg"
lettuce = "http://images.com/lettuce.jpg"
pumpkin = "http://images.com/pumpkin.jpg"
I want to remove all text except the URLs fr...
What I need to do is change a string such as "CN=bobvilla, OU=People, DC=example, DC=com" (can have many DC='s in the string) to "example.com"
I have this method but It seems sloppy to me and wanted to see if anyone had a better idea.
my $str = "CN=bobvilla, OU=People, DC=example, DC=com";
print "old: $str\n";
while($str =~ s/DC=([^,]+...
I have a huge list of URL's, in the format:
http://www.example.com/dest/uk/bath/
http://www.example.com/dest/aus/sydney/
http://www.example.com/dest/aus/
http://www.example.com/dest/uk/
http://www.example.com/dest/nor/
What RegEx could I use to get the last three URL's, but miss the first two, so that every URL without a city attache...