[Solved] Regular expression for phone numbers

If the first part of an alternation matches, then the regex engine doesn’t even try the second part. Presuming you want to match only three-digit, 11 digit, or 11 digit hyphen 1 digit numbers, then you can use lookarounds to ensure that the preceding and following characters aren’t digits. (?<!\d)(\d{3}|\d{11}|\d{11}-\d{1})(?!\d) 2 solved Regular expression for … Read more

[Solved] Regular Expressions in Java replace odd # of slashes

Pattern p = Pattern.compile(“(?<!/)/(//)*(?!/)”); Matcher m = p.matcher(inputString); String outputStr = m.replaceAll(“$0$0”); (?<!/) makes sure there are no slashes right before the match; /(//)* matches an odd number of slashes; (?!/) makes sure there are no slashes right after the match. The replacement string is $0$0, which doubles up the matched slashes. I’ve tested this … Read more

[Solved] Regex not matching all the paranthesis substrings [duplicate]

Parenthesis in regular expressions are used to indicate groups. If you want to match them literally, you must ‘escape’ them: import re found = re.findall(r’\(.*?\)’, text) print(found) Outputs: [‘(not all)’, ‘(They will cry “heresy” and other accusations of “perverting” the doctrines of the Bible, while they themselves believe in a myriad of interpretations, as found … Read more

[Solved] python replace string at 2 parts in one line [duplicate]

You can use the Python replacement regex engine to do recursion and the replacement you want. Regex r”LTRIM\(RTRIM(\((?:(?>(?!LTRIM\(RTRIM\(|[()])[\S\s])+|\(|(?R))*\))\)” Replace with r”TRIM\1″ Sample import regex src=””‘ .. LTRIM(RTRIM(AB.ITEM_ID)) AS ITEM_NUMBER, .. REPLACE(LTRIM(RTRIM(NVL(AB.ITEM_SHORT_DESC,AB.ITEM_DESC))),’,’,”) AS SHORT_DESC .. LTRIM(RTRIM(AB.ITEM_ID))** AS ITEM_NUMBER,** ”’ srcnew = regex.sub(r”LTRIM\(RTRIM(\((?:(?>(?!LTRIM\(RTRIM\(|[()])[\S\s])+|\(|(?R))*\))\)”, r”TRIM\1″, src) print( srcnew ) see https://repl.it/repls/DelightfulSatisfiedCore#main.py 1 solved python replace string at 2 … Read more

[Solved] Extract title from name in c# [closed]

I would recommend regex for a clean way to get the title. Regex regex = new Regex(@”^(Mr|Ms|Dr|Sr)\.”); Match match = regex.Match(“Mr.ABC”); Console.WriteLine(match.Value); 2 solved Extract title from name in c# [closed]

[Solved] Groups in regular expressions (follow up)

It creates a custom regex pattern – explanation as below Name (\w)\w* Name (\w)\w* Options: Case insensitive Match the character string “Name ” literally (case insensitive) Name Match the regex below and capture its match into backreference number 1 (\w) Match a single character that is a “word character” (letter, digit, or underscore in the active … Read more

[Solved] C# Remove Phone Number from String? [closed]

This should help: var myRegex = new Regex(@”((\d){3}-1234567)|((\d){3}\-(\d){3}\-4567)|((\d){3}1234567)”); string newStringWithoutPhoneNumbers = myRegex.Replace(“oldStringWithPhoneNumbers”, string.Empty); 1 solved C# Remove Phone Number from String? [closed]

[Solved] Parsing Java code with Java

People often try to parse HTML, XML, C or java with regular expressions. With enough efforts and tricks, lot of amazing things are possible with complex combinations of regex. But you always end up with something very incomplete and not efficient. Regex can’t handle complex grammars, use a parser, either generic or specific to java. … Read more

[Solved] Need help to split a string [closed]

I believe I have found a solution. Not sure if it is the best way, but I am using regex to extract what need string pattern = @”[0-9][0-9 /.,]+[a-zA-Z ]+”; string input = line; var result = new List<string>(); foreach (Match m in Regex.Matches(input, pattern)) result.Add(m.Value.Trim()); return result; This piece of code returns what I … Read more

[Solved] how to remove all tag in c# using regex.replace [closed]

You should never use regex to parse html, you need html parser. Here is an example how you can do it. You need to add this reference in your project: Install-Package HtmlAgilityPack The code: static void Main(string[] args) { string html = @”<!DOCTYPE html> <html> <body> <h1>My First Heading</h1> <p>My first paragraph.</p> <table> <tr> <td>A!!</td> … Read more

[Solved] python url extract from html

Observe Python 2.7.3 (default, Sep 4 2012, 20:19:03) [GCC 4.2.1 20070831 patched [FreeBSD]] on freebsd9 Type “help”, “copyright”, “credits” or “license” for more information. >>> junk=”’ <a href=””http://a0c5e.site.it/r”” target=_blank><font color=#808080>MailUp</font></a> … <a href=””http://www.site.it/prodottiLLPP.php?id=1″” class=””txtBlueGeorgia16″”>Prodotti</a> … <a href=””http://www.site.it/terremoto.php”” target=””blank”” class=””txtGrigioScuroGeorgia12″”>Terremoto</a> … <a class=”mini” href=”http://www.site.com/remove/professionisti.aspx?Id=65&Code=xhmyskwzse”>clicca qui.</a>`”’ >>> import re >>> pat=re.compile(r”’http[\:/a-zA-Z0-9\.\?\=&]*”’) >>> pat.findall(junk) [‘http://a0c5e.site.it/r’, ‘http://www.site.it/prodottiLLPP.php?id=1’, ‘http://www.site.it/terremoto.php’, ‘http://www.site.com/remove/professionisti.aspx?Id=65&Code=xhmyskwzse’] … Read more

[Solved] Regex from javascript to java

Matcher matcher = Pattern.compile(“c”).matcher(“abcde”); System.out.println(matcher.find()?matcher.start():-1); Matcher matcher2 = Pattern.compile(“[^\\d]”).matcher(“123bed567”); System.out.println(matcher2.find()); Matcher matcher3 = Pattern.compile(“\\d”).matcher(“asdgh”); System.out.println(matcher3.find()?matcher3.group():null); 2 solved Regex from javascript to java

[Solved] PowerShell expression

It takes the contents of a file ‘InputName’, runs it through a regular expression and outputs it to the file ‘OutputName’. The expression takes something in front of a comma, plus the comma itself and concatenates it with something that’s behind a double backslash, some text, a backslash, some text and another backslash. So it … Read more