Posts

Showing posts with the label regex

Learning Regular Expressions [closed]

Learning Regular Expressions [closed] I don't really understand regular expressions. Can you explain them to me in an easy-to-follow manner? If there are any online tools or books, could you also link to them? As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. If this question can be reworded to fit the rules in the help center, please edit the question. This question's answers are a collaborative effort: if you see something that can be improved, just edit the answer to improve it! No additional answers can be added here 1 Answer 1 The most important part is the concepts. Once you understand how...

jq: Select property value using regex

jq: Select property value using regex I have the following json Object: { "foo": { "name": "Name 1", "color": "green", "something_else": { "name" : "Name 2" } }, "bar": { "name": "Something else", "color": "red" } } To get all possible parents properties of the property called "name" using jq I tried : path(recurse|select(.name? !=""))[0] And it works and give back : "foo" "foo" "bar" Now I want to apply regex to filter the property value, say I want to consider only all properties called name that have a value beginning with "Name" and followed by a number like "Name 2" , to get: name "Name 2" "foo" "foo" I tried this: path(recurse|select(.name? =~ match(/Name */)))[0] How to use mat...

regex : get part of text from url data

regex : get part of text from url data I have many of this type of url : http://www.example.com/some-text-to-get/jkl/another-text-to-get I want to be able to get this : ["some-text-to-get", "another-text-to-get"] I tried this : re.findall(".*([[a-z]*-[a-z]*]*).*", "http://www.example.com/some-text-to-get/jkl/another-text-to-get") but it's not working. Any idea ? 4 Answers 4 You can use a lookbehind and lookahead: import re s = 'http://www.example.com/some-text-to-get/jkl/another-text-to-get' final_result = re.findall('(?<=.w{3}/)[a-z-]+|[a-z-]+(?=$)', s) Output: ['some-text-to-get', 'another-text-to-get'] I want only lowercase words, is that possible to do ? Can't make it work with [a-z] – Mohamed AL ANI 21 mins ago ...

Invalid regular expression error in angular directive

Invalid regular expression error in angular directive Condition: Contents can only contain characters from the following set: a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 / - ? : ( ) . , ' + • Contents may NOT begin with ‘/’ • Contents may NOT contain ‘//’ export function directDebitValidator(nameRe: RegExp): ValidatorFn { return (control: AbstractControl): { [key: string]: any } | null => { const directDebitID = nameRe.test(control.value); return directDebitID ? { 'directDebit': { value: control.value } } : null; }; } @Directive({ selector: '[directDebit]', providers: [{ provide: NG_VALIDATORS, useExisting: DirectDebitValidatorDirective, multi: true }] }) export class DirectDebitValidatorDirective { validate(control: AbstractControl): { [key: string]: any } | null { return control.value ? di...

How can i block a specific URL while my site fetches each and every video and user pages from youtube using V3 api?

How can i block a specific URL while my site fetches each and every video and user pages from youtube using V3 api? I use php script to fetch video pages and user pages from youtube using api v3, the script includes the blocking of videos feature but does not support blocking user pages, my hosting team is unable to help me out, so iam here at stackoverflow seeking help. Please provide some detail explanation .. and in my opinion you have to read api documentation – Er. Amit Joshi Jul 2 at 4:12 Hey there, i want to block specific pages fetched by youtube api, ( what currently scrpot does, it fetch all urls) – Decent Nil Jul 2 at 4:14 put those url's or id's of...

How to compare between different date formats?

How to compare between different date formats? I have four different date formats that I will store in a DB, Then show the latest ones. The four different formats: $a = '27. júní 2018 04:53'; $b = 'Friday, 09 March 2018'; $c = 'Fri, 29 Jun 2018 11:00:00 GMT'; $d = 'Mon, 18 Jun 2018 06:52:20 +0000'; They will be stored in a MYSQL Database. What should I do with them? Can SQL or MYSQL date type do the work? Should I convert them using strtotime() ? strtotime() Should I extract some data from specific ones to male them match? Can SQL or MYSQL date type do the work? Maybe you should try before asking the question. Please post the code that you have tried and explain which part is not working. – Dvorog Jul 1 at 10:38 php.net/manual/en/function.strtotime.php – WPZA ...

Removing commas from numbers with .NET regex

Image
Removing commas from numbers with .NET regex So I'm processing a report that (brilliantly, really) spits out number values with commas in them, in a .csv output. Super useful. So, I'm using (C#)regex lookahead positive and lookbehind positive expressions to remove commas that have digits on both sides. If I use only the lookahead, it seems to work. However when I add the lookbehind as well, the expression breaks down and removes nothing. Both ends of the comma can have arbitrary numbers of digits around them, so I just want to remove the comma if the pattern has one or more digits around it. Here's the expression that works with the lookahead only: str = Regex.Replace(str, @"[,](?=(d+)),""); Here's the expression that doesn't work as I intend it: str = Regex.Replace(str, @"[,](?=(d+)?<=(d+))", ""); What's wrong with my regex! If I had to guess, there's something I'm misunderstanding about how lookbehind works. Any id...

Regex to match all outermost pair of bracket into array

Regex to match all outermost pair of bracket into array I want a regex to match all outermost pair of bracket into array with their contents in them even if their content could be nested. This was my code this gives expected output console.log("52*((6*8)-4+3^(7+5))".match(/ *(([^]*)) */g)) /* => [ '((6*8)-4+3^(7+5))' ] correct*/ But this doesn't give expected output console.log("52*(6*8)-4+3^(7+5)".match(/ *(([^]*)) */g)) /* => [ '(6*8)-4+3^(7+5)' ] incorrect expected [ '(6*8)', '(7+5)' ]*/ please if anyone understand this problem help me /((.*)/)g try that. – Alex Jul 1 at 12:42 /((.*)/)g Apart from abusing regex features that elevate it above regular expressions, parsing nested brackets of unknown depth is impossible. – ASDFGert...

Getting back the right amount of matches

Getting back the right amount of matches I have a simple problem, but I've had a hard time find a simple and effective solution to it. Since I didn't have any success with way I posted what I need to solve the first and the second times, I am going to try it a third time with a more direct question. After searching the web, I found a solution to dealing with German and French characters, but the underlying problem with the matches I get is the same. I simplified the script, so that anyone can try it out. <?php $lines=array("Ich weiß wirklich nicht, womit er prahlt!: I really don't know what he's bragging of!","Worüber hat er gesprochen?: what did he talked about?"); foreach($lines as $line){ preg_match_all('/b([A-Za-zäöüÖÄÜßs.,'!?])+([A-Za- zs.;'-!?]+)/',$line,$lines1,PREG_PATTERN_ORDER); echo 'results = '.$lines1[0][0].'<BR>'; } ?> From preg_match_all I only get two matches: results = Ich wei� wirklich...

Get partial class name and text inside div using regex

Get partial class name and text inside div using regex I need to get two values from this HTML, which is either an error or a success from toast-* , and also get the value inside the toast-message : toast-* toast-message <div class="toast toast-error" style=""> <div class="toast-message">You have failed.</div> </div> <div class="toast toast-success" style=""> <div class="toast-message">You have succeed. </div> The div elements only show once at a single time, which can be either error or success. div Is there any way I can use regex, so I can extract the value within array so it either: ['success', 'You have succeed.'] or ['error', 'You have failed.'] Any help would be greatly appreciated. Thanks! Why do you want to use a regular expression here? Do you have a reference to the elements? – CertainP...

extract strings matching a regular expression vb.net

extract strings matching a regular expression vb.net i have a text like following 1. 2. 3. 4. Test data 1 Please identify the ID number: # 1016108 Please check if the number above matches the number below. The comparison result should be "True or False". You should only compare the 7 digits: a. #1016108 Please try to compare the results from Google OCR Engine and Microsoft OCR Engine. And choose the one that suits for this task better. Here is a third number # 123456, please DO NOT use this number for this task i need to extract the numbers which are followed by # alone but not the third number as there is a text "third number" infront of it. also it is mentioned that i should not take this number for matching. so i need to extract first 2 numbers(only numbers) and match and say the result . Code from Comment Dim mc As MatchCollection Dim i As Int32 mc = Regex.Matches(txt, "[#]([0-9]+)") Dim results(mc.Count - 1) As String For i = 0 To results.Length - 1 ...

Regex for extracting all complex dates formats from a string in python

Regex for extracting all complex dates formats from a string in python I have following string: dateEntries = "04-20-2009; 04/20/09; 4/20/09; 4/3/09; Mar 20, 2009; March 20, 2009; Mar. 20, 2009; Mar 20 2009; 20 Mar 2009; 20 March 2009; 2 Mar. 2009; 20 March, 2009; Mar 20th, 2009; Mar 21st, 2009; Mar 22nd, 2009; Feb 2009; Sep 2009; Oct 2010; 6/2008; 12/2009; 2009; 2010" Here I want to extract all mentioned dates using regex . As an attempt I have written following regex : regex regex import re regEx = r'(?:d{1,2}[-/th|st|nd|rds]*)?(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[a-zs,.]*(?:d{1,2}[-/th|st|nd|rd)s,]*)?(?:d{2,4})' re.findall(regEx, dateEntries) I was expecting this to work but it only return subset of dates. A = ['Mar 20, 2009', 'March 20, 2009', 'Mar. 20, 2009', 'Mar 20 2009', '20 Mar 2009', '20 March 2009', '2 Mar. 2009', '20 March, 2009', 'Mar 20th, 2009', 'Mar 21s...

Laravel 5.6 - Validate Numbers and spaces

Laravel 5.6 - Validate Numbers and spaces In Laravel 5.6 I am validating alphabetic characters and spaces only in regex like this.. 'name' => 'required|regex:/^[pLs-]+$/u', This works as far as I can see, I am now trying to validate numbers only and spaces like this.. 'telephone' => 'required|regex:/[0-9 ]+/', But this is not working and allows me to enter 'f4' where it should fail. Where am I going wrong? Try 'regex:/(^[0-9 ]+$)+/' – Vincent Decaux Jul 1 at 10:29 'regex:/(^[0-9 ]+$)+/' 1 Answer 1 [0-9 ]+ will match 4 in f4 [0-9 ]+ 4 f4 Try using anchors to assert the start and the end of the line ^ and $ ^ $ ^[0-9 ]+$ ^[0-9 ]+$ Note that this will also match whitespaces only because the ch...