[Solved] Replace YYYY-MM-DD dates in a string with using regex [closed]

import re from datetime import datetime, timedelta dateString = “hello hello 2017-08-13, 2017-09-22” dates = re.findall(‘(\d+[-/]\d+[-/]\d+)’, dateString) for d in dates: originalDate = d newDate = datetime.strptime(d, “%Y-%m-%d”) newDate = newDate + timeDelta(days=5) newDate = datetime.strftime(newDate, “%Y-%m-%d”) dateString = dateString.replace(originalDate, newDate) Input: hello hello 2017-08-13, 2017-09-22 Output: hello hello 2017-08-18, 2017-09-27 6 solved Replace YYYY-MM-DD … Read more

[Solved] Regex to match specific words in java [closed]

I would not recommend a regex for this. But it is possible: boolean foundMatch = subjectString.matches( “(?x) # Verbose regex:\n” + “(?!.*(AB|CD|EF).*\\1) # Make sure there are no dupes in the string\n” + “\\s* # Match optional whitespace.\n” + “(?:AB|CD|EF) # Match one of the three candidates\n” + “(?: # Try to match…\n” + ” … Read more

[Solved] Remove some specific string with special character

You can use this regex, \s+\[.*(?=\b\d+) and replace it with empty string. You start with one or more whitespace then match a [ using \[ and then .* consumes all the characters greedily and only stops when it sees a number using positive look ahead (?=\b\d+) Regex Demo 0 solved Remove some specific string with … Read more

[Solved] Java – Regex only 0 or 5 [closed]

You can use either “0|5” or “[05]”. The first is an alternative, the second is a character class. They will behave identically. See the documentation for Pattern for more information on the building blocks for regular expressions. solved Java – Regex only 0 or 5 [closed]

[Solved] Get number from the string (RegExp) [closed]

There are a lot of answers to this question in stackoverflow. Next time search before you ask! Here is a simple code which gives what you want: String str= “animal 1 animal”; Pattern p = Pattern.compile(“-?\\d+”); Matcher match = p.matcher(str); while (match.find()) { System.out.println(match.group()); } It is the same with your other Strings.. just change … Read more

[Solved] How to make a this specific Pattern [closed]

There’s two different ways to go about this: Build a parser – much work, but very flexible and possibly best performance (depending on implementation) Use a regular expression. In your case this could be something like (\d{2,3}\.)+\d{2,3} (shortest string matched should be “111.11”) 2 solved How to make a this specific Pattern [closed]

[Solved] Split a string between special characters [closed]

Use a regular expression with a capture group and RegEx.exec() to extract any substrings between three apostrophes. The pattern uses lazy matching (.*?) to match any sequence of characters (including none) between the apostrophes. const str = ” My random text ”’tag1”’ ”’tag2”’ “; re = /”'(.*?)”’/g; matches = []; while (match = re.exec(str)) { … Read more

[Solved] c# string manipulation add * for plain word

some how I achieved it in lengthy way …Not sure if any shortcut is there to achieve… var keywords_updated = (keywords.Replace(” “, “* “)); keywords_updated = keywords_updated.EndsWith(““) ? keywords_updated : keywords_updated + ““; MatchCollection col = Regex.Matches(keywords, “\\”(.?)\\””);//Regex.Matches(keywords, “(?<=\”)[^\”](?=\”)|[^\” ]+”); var data = col.Cast().Select(m => m.Value).ToList(); Console.WriteLine(data.Count); foreach (var item in data) { keywords_updated = … Read more

[Solved] Regular expressions in Notepad++. How make pattern that could be use in a few lines

To answer as a general exercise, run replace all cout.*<<.*\K<< with +, many times until it can’t match. replace all cout.*<<.*\Kendl with “\\n”, many times replace all cout.*<<.*\K(?<!\))(?=;) with \) replace all cout.*<<with Console.Write\( from perlre \K (Keep the stuff left of the \K) (?<!..) A zero-width negative lookbehind assertion. (?=..) A zero-width positive lookahead … Read more

[Solved] How to add dots between every two digits of a six digit substring?

You want to use a replace technique (in whatever language/environment you are using) on your substrings by capturing like this: (\d{2})(\d{2})(\d{2}) *note the curly brackets are for improved efficiency. And replace with: $1.$2.$3 Here is a demo link. Here is a SO page discussing the execution of replacements on nano. 1 solved How to add … Read more

[Solved] Java :- String search in proximity manner

Here is a very naive way without regex. public class NotElegant { public static void main(String[] args){ String text = “doctors found many cancer related chest problems in japan during second world war.”; String term = “cancer problems”; System.out.println(getWordsNearEachOther(text,term,3)); } public static String getWordsNearEachOther(String text, String term, int distance){ String word1= term.split(” “)[0]; String word2= … Read more

[Solved] How to replace a pattern in a string

I would do this for the links <%= ([1,2,3]- [params[:x]]).each do |link_number| %> <%= link_to “Version #{link_number}”, “/page?x=#{link_number}” %> <% end %> This way everytime the page is loaded the link to the other 2 versions will exist. You could handle the partials through the controller (which seems better) or use something like: <%= render … Read more

[Solved] Regex: find word with extra characters

I’m going to demonstrate required steps to cook a regex for word help but the requirements are not clear, rules are not strict hence some drawbacks are usual. \bh+[a-z&&[^e]]*e+[a-z&&[^le]]*l+[a-z&&[^ p l e ]]*p+\b ^ ^^ ^ ^ ^ | || | |–|-> [#2] | || |-> [#1] | ||-> Previous char(s) [#2] | |-> [#1] … Read more

[Solved] Split multiple Words in a string [closed]

I am unsure about the language, but for C# you can use the following: string s1 = “1 AND 1 OR 1”; string s2 = s1.Replace(“AND”, “,”).Replace(“OR”, “,”); Console.WriteLine(s2); Which doesn’t use regular expressions. If you want an array, you can use the following: string s1 = “1 AND 1 OR 1”; string[] s2 = … Read more