Posts

Showing posts with the label regex

Python regex needed for format: 'delete([any text here])'

Python regex needed for format: 'delete([any text here])' I am a total regex beginner. I want to create a regular expression that strictly allows the word delete followed by two closed parenthesis that contain any kind of characters (http://www.waynesworld1.com) . delete (http://www.waynesworld1.com) If I put it all together, it should accept the following: delete(http://www.waynesworld123.com) . delete(http://www.waynesworld123.com) Let me emphasize that the regex should strictly accept delete() and shouldn't accept elete() . As long as the user types in delete() anything is acceptable within the parenthesis ( example: this would be fine delete(12!@Ww) delete() elete() delete() delete(12!@Ww) How can I craft this regex in Python? So far all I have is /delete/ for my regex. /delete/ Why the downvote? This is a perfectly reasonable question that is well constructed and very understandable. I have done previous research and haven't found a...

Difference between r'^specific expression$' and r'specific expression' [duplicate]

Difference between r'^specific expression$' and r'specific expression' [duplicate] This question already has an answer here: My doubt is that I came across a regex which checks whether a password is strong or not. What is the impact of ^ and $ in this expression. a = compile(r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$') It has ^ and $ signs in it. But the below code works the same as above. a = compile(r'(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}') If so why are they been used in the above code. Or is there reason for its usage. Thanks in advance! This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. You would not ask the difference if you knew why caret and dollar sign are being used. Please check the marked question. – revo Jul 1 at 10:27 ...

Replace http links with anchor tag

Replace http links with anchor tag So i'm building a chat-client where i read the incoming-messages through json. However, I would like to be able to convert URLs to clickable anchor-tags instead. I've looked around but haven't really found any posts asking or getting an answer about this. This is my current code: if (json.type === 'message') { var val; var str = json.data.text; //message-string var here = str.match("([^s]+)"); // match any word until space <---| merge if (!here.search(/^http[s]?:///)){ //if it contains http / https <---| these? val = '<a href="' + here + ""> [Link] </a>"; } addMessage(json.data.author, val, json.data.color, new Date(json.data.time)); } else { console.log('Hmm..., I've never seen JSON like this:', json); } Thanks 1 Answer 1 You're never usin...

generic regex to capture various optional groups

generic regex to capture various optional groups I am looking for a method to select, using regex, lines containing various groups, some of them optional, and capture the groups - the found ones, of course. After reading here on stackoverflow and many experiments I came up with this general enough approach: ^.*?(?:.*?(aaa).*?|.*?).*?(xxx).*?(yyy).*?(?:.*?([^ n]+).*?|.*?).*?$ So the general term for optional groups is: (?:.*?(blabla).*?|.*?) The above approach has backtracking problems in case of: Any ideea how to create a generic enough regex able to capture optional groups? By generic I mean, like in the example I found, easily scalable up for various group patterns. Thanks. Hi. Please include a tag for one specific engine or language (perl, pcre, c#, etc…). Regular expression questions get better answers if they… show the pattern that isn't working, provide some examples of input text that should match, and also ones that shouldn't match . Describe...

RegEx - find a word inside a specific section of a file

RegEx - find a word inside a specific section of a file I am trying to set up an alarm in a piece of weather software to look at a forecast for my area and tell me if the word "severe" appears in the upcoming forecast. I am looking at the following text file (shortened down a bit): 000 FPUS55 KBOU 301529 ZFPBOU Zone Forecast Product for Northeast Colorado National Weather Service Denver/Boulder CO 929 AM MDT Sat Jun 30 2018 COZ042-044-010615- Northeast Weld County-Morgan County- including Briggsdale, Grover, Pawnee Buttes, Raymer, Stoneham, Brush, Fort Morgan, Goodrich, and Wiggins 929 AM MDT Sat Jun 30 2018 .REST OF TODAY...Chance of thunderstorms early in the afternoon. Thunderstorms likely late in the afternoon. Some thunderstorms may be severe with large hail. Highs 68 to 74. Northeast winds 10 to 15 mph with gusts to around 25 mph. Chance of thunderstorms 70 percent. .TONIGHT...Mostly cloudy with a 30 percent chance of thunderstorms in the evening, then mostly clear aft...

Regex Extract URL's and their labels from HTML file

Regex Extract URL's and their labels from HTML file I have a large html file exported from Google doc. When opened in a text editor it appears as a single line. There are many URL's there which I need to extract. They appear in this form: <a class="c13" href="https://www.google.com/url?q=https://example.com/page1/&amp;sa=D&amp;ust=1530382105580000">Text Label One</a>SOME HTML TEXT HERE<a class="c13" href="https://www.google.com/url?q=https://example.com/page2/&amp;sa=D&amp;ust=1530382105719000">Text Label Two</a> <a class="c13" href="https://www.google.com/url?q=https://example.com/page1/&amp;sa=D&amp;ust=1530382105580000">Text Label One</a>SOME HTML TEXT HERE<a class="c13" href="https://www.google.com/url?q=https://example.com/page2/&amp;sa=D&amp;ust=1530382105719000">Text Label Two</a> So far I found this solution (?...

HAProxy and reqrep path rewriting with redirect configuration

HAProxy and reqrep path rewriting with redirect configuration With HA Proxy 1.5 I need to rewrite URL from http://main.domain.com/my-foo to http://othersite.com:8081/other-bar http://main.domain.com/my-foo http://othersite.com:8081/other-bar Here is what I tried: frontend ft_def bind :80 mode http acl has_special_uri path_beg /my-foo use_backend def if has_special_uri default_backend def backend def mode http option forwardfor reqirep ^([^ ]* )/my-foo(.*) 1/other-bar2 server myserver othersite.com:8081 This works: URL http://main.domain.com/my-foo/home.html becomes http://othersite.com:8081/other-bar/home.html http://main.domain.com/my-foo/home.html http://othersite.com:8081/other-bar/home.html and in the browser the initial URL http://main.domain.com/my-foo/home.html appears. http://main.domain.com/my-foo/home.html I...

What pattern to check on an SQL query for possible injection?

What pattern to check on an SQL query for possible injection? I want to detect possible SQL injection atack by checking the SQL query. I am using PDO and prepared statement, so hopefully I am not in the danger of getting attacked by someone. However, what I want to detect is the possibility of input/resulting query string that may become a dangerous query. For example, my app--properly--will never generate "1=1" query, so I may check the generated query string for that, and flag the user/IP producing that query. Same thing with "drop table", but maybe I can check only by looping the input array; or maybe I should just check to the generated query all over again. I am using MySQL, but pattern for other drivers are also appreciated. I have read RegEx to Detect SQL Injection and some of the comments are heading in this direction. To my help, I'm developing for users that rarely use English as input, so a simple /drop/ match on the query may be enough to log the use...

match any character except forward slash

match any character except forward slash I'm parsing data from my satellite box to receive music information to display on my iPad. One particular string I'm interested in looks like this; "title": ""Free Falling"" I want to match Free Falling only so that it can be displayed. I tried "title": "(.*)" but it returns "Free Falling" "Free Falling" I tried negating the forward slashes [^/] but the when tested, the first space between Free and Falling matches the entire pattern [^/] How do I match the words Free Falling only, without the quotes and forward slashes and retain the white space? Welcome to Stackoverflow. Is it in JSON? – revo Jun 30 at 14:00 Try this "title": "\"(.*)\"" . ...

Jupyter Notebook's search and replace not as greedy as regex101's javascript

Image
Jupyter Notebook's search and replace not as greedy as regex101's javascript I have a number of logger.*() functions I want to convert to simple print() statements in a Jupyter Notebook. I already changed the beginning of the lines: logger.*( . Now I need to fix the tail and change ", e to " % (e : logger.*() print() logger.*( ", e " % (e print("(%s):n" " Failed to load logger" % (e, )) logger.error("(%s):n" " Validation Testing errors occurred. '%s'", e, report_file) logger.critical("(%s):n" " Failed to return Parsed Report " " in debug mode.", e) logger.critical("(%s):n" " Error loading template.", e) Using Regex101 to test my javascript Regex, I wrote print("[sS.]*(", e) But in Jupyter's find and replace, this only captures up to print("(%s)n" . print("(%s)n" ...

Poor regex performance for word matching on postgres

Poor regex performance for word matching on postgres I have a list of blocked phrases and I want to match for the existence of those phrases in user inputed text, but performance is very bad. I am using this query : SELECT value FROM blocked_items WHERE lower(unaccent( 'my input text' )) ~* ('[[:<:]]' || value || '[[:>:]]') LIMIT 1; After my investigation I found out that world boundries [[:<:]] and [[:>:]] perform very badly knowing that blocked_items has 24k records in it. [[:<:]] [[:>:]] For instance when I try to run this one: SELECT value FROM blocked_items WHERE lower(unaccent( 'my input text ' )) ilike ('%' || value || '%') LIMIT 1; it's very fast compared to the first one. The problem is that I need to keep the test for word boundries. This check is performed frequently on a large program so the performance is very important for me. Do you guys have any suggestions for making this faster? EXPLIAN ANALYZE s...

Regular Expression to extract data between two bracket

Regular Expression to extract data between two bracket For example I have a string line as follows What is your family Occupation? [RMB 2011] I want to extract two data from here. The RMB part can be of any length. I have used following regex pattern to extract the data ^[([A-Z]{3}sdddd[)]]$ But it does not match anything in the string. Please let me know what I am doing wrong. 1 Answer 1 You do not need the string start with ] . Try this online: ] [([A-Z]{3})s(d{4})] And if RMB part can be of any length , you can change [A-Z]{3} to [A-Z]{1,} . [A-Z]{3} [A-Z]{1,} Exactly what I wanted :). Thanks – Mars Moon Jun 30 at 9:54 By clicking "Post Your Answer", you acknowledge that you have read our updated ...

RegEx match numbers which have n repeating digits at the end

RegEx match numbers which have n repeating digits at the end I want to match numbers which have exact n repeating digits at the end in Javascript. However, my regex matches n or more than n digits at the end, and I can't seem to fix that. i.e n=3, match these: 12333 222 1233334333 12333 222 1233334333 Not match these: 11 12344 122233 123333 11 12344 122233 123333 My regexs(don't work): (d)1{2}$ [^1](d)1{2}$ (d){3}(?!1)$ (d)1{2}$ [^1](d)1{2}$ (d){3}(?!1)$ Another variant: ^(?:(d)(?!1{3}$))*?(d)2{2}$ – bobble bubble Jun 30 at 14:51 ^(?:(d)(?!1{3}$))*?(d)2{2}$ 3 Answers 3 Try this - match the digit right before the repeating digits start, use negative lookahead for said digit, then match 3 repeating digits: const strs = [ '12333', '222...