regex

Remove date from string with regular expressions

假如想象 提交于 2021-02-05 06:37:46
问题 Ok, so I have a string $title_string which could look like any of the following: $title_string = "20.08.12 First Test Event"; $title_string = "First Test event 20/08/12"; $title_string = "First Test 20.08.2012 Event"; I need to end up with two variables: $title = "First Test Event"; $date = "20.08.12"; The formatting for the date should be converted to full-stops, regardless of what it was originally. The Regex string that I started with looks something like this: $regex = ".*(\d+\.\d+.\d+).*

Remove date from string with regular expressions

你说的曾经没有我的故事 提交于 2021-02-05 06:37:30
问题 Ok, so I have a string $title_string which could look like any of the following: $title_string = "20.08.12 First Test Event"; $title_string = "First Test event 20/08/12"; $title_string = "First Test 20.08.2012 Event"; I need to end up with two variables: $title = "First Test Event"; $date = "20.08.12"; The formatting for the date should be converted to full-stops, regardless of what it was originally. The Regex string that I started with looks something like this: $regex = ".*(\d+\.\d+.\d+).*

Regex for removing Commas within brackets

血红的双手。 提交于 2021-02-05 06:36:05
问题 I am stuck at writing the regex which needs me to remove comma inside brackets. The commas outside should stay as is Here's what I need Input :(37.400809377128354, -122.05618455969392) , (37.3931723332768, -121.89276292883454) Output :(37.400809377128354 -122.05618455969392) , (37.3931723332768 -121.89276292883454) Thanks in Advance! 回答1: You can use this regex which uses positive look ahead to discard matching a comma that is outside the parenthesis, ,(?=[^()]*\)) Demo var s = "(37

Can I use variables in pattern in Regex (C#)

*爱你&永不变心* 提交于 2021-02-05 06:32:04
问题 I have some HTML-text, where I need to replace words to links on them. For example, I have text with word "PHP", and want to replace it with <a href="glossary.html#php">PHP</a>. And there are many words that I need to replace. My code: public struct GlossaryReplace { public string word; // here the words, e.g. PHP public string link; // here the links to replace, e.g. glossary.html#php } public static GlossaryReplace[] Replaces = null; IHTMLDocument2 html_doc = webBrowser1.Document

Regular expression to match strings that do NOT contain all specified elements

浪尽此生 提交于 2021-02-05 06:30:51
问题 I'd like to find a regular expression that matches strings that do NOT contain all the specified elements, independently of their order. For example, given the following data: one two three four one three two one two one three four Passing the words two three to the regex should match the lines one two , one three and four . I know how to implement an expression that matches lines that do not contain ANY of the words, matching only line four : ^((?!two|three).)*$ But for the case I'm

A regular expression that will allow a string with only one Capital Letter

一个人想着一个人 提交于 2021-02-05 06:30:46
问题 The string should be 6 - 20 characters in length. And it should contain 1 Capital letter. I can do this in code using C#: string st = "SomeString" Regex rg = new Regex("[A-Z]"); MatchCollection mc = rg.Matches(st); Console.WriteLine("Total Capital Letters: " + mc.Count); if (mc.Count > 1) { return false; } But what i really want is a Regular expression that will match my string if it only contains one capital. The string can start with a common letter and should have only letters. 回答1: This

How to split a string at uppercase letters in two scripts

假装没事ソ 提交于 2021-02-05 06:13:08
问题 I have the following text format text = "MyNameIsΔημητρης" and I want to split it in a list textlist = ["My","Name","Is","Δημητρης"] If it was only english letters I could do import re re.findall('[A-Z][^A-Z]*', 'TheLongAndWindingRoad') How can I add the greek letters? 回答1: You may create a regex for re using custom character classes for all lower- and uppercase Unicode letters. See Python regex for unicode capitalized words for details how to do that. Here is an example Python code: import

Regexp to remove all html tags except <br>

自闭症网瘾萝莉.ら 提交于 2021-02-05 06:12:12
问题 I'm trying to make a regexp in javascript to remove ALL the html tags from an input string, except <br> . I use /(<([^>]+)>)/ig for the tags and have tried a few things like adding [^(br)] to it, but I'm just getting confused now. Could anyone help? I'm sure it's going to be a speed contest between SO gurus, so if the answer explains the logic of the expression, I'll choose it over the others. Edit : To all the 'don't do it' people, let me quote the following from Stack Overflow While it is

Capturing repeating groups in GO

你说的曾经没有我的故事 提交于 2021-02-05 06:11:10
问题 I'm trying to create a function that can parse strings which consist of an uppercase word followed by zero or more arguments which are encapsulated in double quotes. For example, each of the following lines: COPY "filename one" "filename two" REMOVE "filename" LIST "x" "y" "z" DISCONNECT The result should be a string (the command) followed by a string[] (the arguments inside the quotes). I created the following regular expression: re1, _ := regexp.Compile(`([A-Z]+)(?: "([^"]+)")*`) results :=

Perl regex with pipes

自闭症网瘾萝莉.ら 提交于 2021-02-05 06:10:03
问题 I'm not exactly a perl monk, so if you could help me digest what does this regex(if it is one) do? my $pathHere = "/some/path/to/file"; my $pathThere = "/some/path/"; $pathHere =~ s|$pathThere||; Perl is not exactly my everyday tool, so I am quite shy on knowledge - I guess it subs the match to the var value, but guessing is not the way to go - the pipes throw me off... Thanks 回答1: In Perl you'd normally use the / as a delimiter in the regexp. $pathHere =~ s/abc/def/; # replace 'abc' with