Search Results

Search found 3825 results on 153 pages for 'regex negation'.

Page 23/153 | < Previous Page | 19 20 21 22 23 24 25 26 27 28 29 30  | Next Page >

  • regex part of url

    - by kyle
    So I'm trying to get the id from a url for youtube.. here is the url http://gdata.youtube.com/feeds/api/videos/kffacxfA7G4/related?v=2 then there's also - in the url too. it wouldn't let me post another url but it's the same as above but with the id ucvkO0x-mL4 how can I grab between videos/ and /related (the id) with regex? I tried to use txt2re.com which is what I always use, but it's not working for this case.. thanks!

    Read the article

  • Help with specific Regex: need to match multiple instances of multiple formats in a single string.

    - by KevenK
    I apologize for the terrible title...it can be hard to try to summarize an entire situation into a single sentence. Let me start by saying that I'm asking because I'm just not a Regex expert. I've used it a bit here and there, but I just come up short with the correct way to meet the following requirements. The Regex that I'm attempting to write is for use in an XML schema for input validation, and used elsewhere in Javascript for the same purpose. There are two different possible formats that are supported. There is a literal string, which must be surrounded by quotation marks, and a Hex-value string which must be surrounded by braces. Some test cases: "this is a literal string" <-- Valid string, enclosed properly in "s "this should " still be correct" <-- Valid string, "s are allowed within (if possible, this requirement could be forgiven if necessary) "{00 11 22}" <-- Valid string, {}'s allow in strings. Another one that can be forgiven if necessary I am bad output <-- Invalid string, no "s "Some more problemss"you know <-- Invalid string, must be fully contained in "s {0A 68 4F 89 AC D2} <-- Valid string, hex characters enclosed in {}s {DDFF1234} <-- Valid string, spaces are ignored for Hex strings DEADBEEF <-- Invalid string, must be contained in either "s or {}s {0A 12 ZZ} <-- Invalid string, 'Z' is not a valid Hex character To satisfy these general requirements, I had come up with the following Regex that seems to work well enough. I'm still fairly new to Regex, so there could be a huge hole here that I'm missing.: &quot;.+&quot;|\{([0-9]|[a-f]|[A-F]| )+\} If I recall correctly, the XML Schema regex automatically assumes beginning and end of line (^ and $ respectively). So, essentially, this regex accepts any string that starts and ends with a ", or starts and ends with {}s and contains only valid Hexidecimal characters. This has worked well for me so far except that I had forgotten about another (although less common, and thus forgotten) input option that completely breaks my regex. Where I made my mistake: Valid input should also allow a user to separate valid strings (of either type, literal/hex) by a comma. This means that a single string should be able to contain more than one of the above valid strings, separated by commas. Luckily, however, a comma is not a supported character within a literal string (although I see that my existing regex does not care about commas). Example test cases: "some string",{0A F1} <-- Valid {1122},{face},"peanut butter" <-- Valid {0D 0A FF FE},"string",{FF FFAC19 85} <-- Valid (Spaces don't matter in Hex values) "Validation is allowed to break, if a comma is found not separating values",{0d 0a} <-- Invalid, comma is a delimiter, but "Validation is allowed to break" and "if a comma..." are not marked as separate strings with "s hi mom,"hello" <-- Invalid, String1 was not enclosed properly in "s or {}s My thoughts are that it is possible to use commas as a delimiter to check each "section" of the string to match a regex similar to the original, but I just am not that advanced in regex yet to come up with a solution on my own. Any help would be appreciated, but ultimately a final solution with an explanation would just stellar. Thanks for reading this huge wall of text!

    Read the article

  • JavaScript - string regex backreferences

    - by quano
    You can backreference like this in JavaScript: var str = "123 $test 123"; str = str.replace(/(\$)([a-z]+)/gi, "$2"); This would (quite silly) replace "$test" with "test". But imagine I'd like to pass the resulting string of $2 into a function, which returns another value. I tried doing this, but instead of getting the string "test", I get "$2". Is there a way to achieve this? // Instead of getting "$2" passed into somefunc, I want "test" // (i.e. the result of the regex) str = str.replace(/(\$)([a-z]+)/gi, somefunc("$2"));

    Read the article

  • Using RegEx to replace invalid characters

    - by yeahumok
    Hello I have a directory with lots of folders, subfolder and all with files in them. The idea of my project is to recurse through the entire directory, gather up all the names of the files and replace invalid characters (invalid for a SharePoint migration). However, i'm completely unfamiliar with Regular Expressions. The characters i need to get rid in filenames are: ~, #, %, &, *, { } , \, /, :, <, ?, -, | and "" I want to replace these characters with a blank space. I was hoping to use a string.replace() method to look through all these file names and do the replacement. So far, the only code i've gotten to is the recursion. I was thinking of the recursion scanning the drive, fetching the names of these files and putting them in a List. Can anybody help me with how to find/replace invalid chars with RegEx with those specific characters?

    Read the article

  • Regex to replace relative link with root relative link

    - by Kendall Hopkins
    I have a string of text that contains html with all different types of links (relative, absolute, root-relative). I need a regex that can be executed by PHP's preg_replace to replace all relative links with root-relative links, without touching any of the other links. I have the root path already. Replaced links: <tag ... href="path/to_file.ext" ... > ---> <tag ... href="/basepath/path/to_file.ext" ... > Untouched links: <tag ... href="/any/path" ... > <tag ... href="protocol://domain.com/any/path" ... >

    Read the article

  • PHP regex to match sentences that contain a year

    - by zen
    I need a regular expression that will extract sentences from text that contain a year in them. Example text: Next, in 1988 the Bradys were back again for a holiday celebration, "A Very Brady Christmas". Susan Olsen (Cindy) would be missing from this reunion, Jennifer Runyon took her place. This was a two hour movie in which the Bradys got together to celebrate Christmas, introducing the world to the spouses and children of the Brady kids. This movie was the highest rated TV-movie of 1988. If the example text was variable $string, I need it to return: $sentenceWithYear[0] = Next, in 1988 the Bradys were back again for a holiday celebration, "A Very Brady Christmas". $sentenceWithYear[1] = This movie was the highest rated TV-movie of 1988. If it's possible to retain the year via regex, I'd use the year within the sentence and eventually insert the sentences into a database like: INSERT INTO table_name (year, sentence) VALUES ('$year', '$sentenceWithYear[x]')

    Read the article

  • regex to match trailing whitespace, but not lines which are entirely whitespace (indent placeholders

    - by Tim
    I've been trying to construct a ruby regex which matches trailing spaces - but not indentation placeholders - so I can gsub them out. I had this /\b[\t ]+$/ and it was working a treat until I realised it only works when the line ends are [a-zA-Z]. :-( So I evolved it into this /(?!^[\t ]+)[\t ]+$/ and it seems like it's getting better, but it still doesn't work properly. I've spent hours trying to get this to work to no avail. Please help. Here's some text test so it's easy to throw into Rubular, but the indent lines are getting stripped so it'll need a few spaces and/or tabs. Once lines 3 & 4 have spaces back in, it shouldn't match on lines 3-5, 7, 9. some test test some test test some other test (text) some other test (text) likely here{ dfdf } likely here{ dfdf } and this ; and this ; Alternatively, is there an simpler / more elegant way to do this?

    Read the article

  • Help with password complexity regex

    - by Alex
    I'm using the following regex to validate password complexity: /^.*(?=.{6,12})(?=.*[0-9]{2})(?=.*[A-Z]{2})(?=.*[a-z]{2}).*$/ In a nutshell: 2 lowercase, 2 uppercase, 2 numbers, min length is 6 and max length is 12. It works perfectly, except for the maximum length, when I'm using a minimum length as well. For example: /^.*(?=.{6,})(?=.*[0-9]{2})(?=.*[A-Z]{2})(?=.*[a-z]{2}).*$/ This correctly requires a minimum length of 6! And this: /^.*(?=.{,12})(?=.*[0-9]{2})(?=.*[A-Z]{2})(?=.*[a-z]{2}).*$/ Correctly requires a maximum length of 12. However, when I pair them together as in the first example, it just doesn't work!! What gives? Thanks!

    Read the article

  • Problem with Regex in .NET (C#)

    - by Craig Bovis
    I'm trying to write a a regex to validate a string to match the following rules. Must start with a-z (case insensitive) Must only contain a-z A-Z 0-9 . - I've put something together based on my limited knowledge and ran it through an online testing tool for a whole bunch of situations and the results were as I had hoped however when I place the pattern into my .NET code it doesn't match correctly. The pattern I am using is, [a-zA-Z][a-zA-Z0-9.\-]* Is this the correct pattern or am I barking up the wrong tree? Some examples of what I'm expecting. craig.bovis - VALID 24craig - INVALID craig@bovis - INVALID craig24 - VALID -craig24 - INVALID craig24.bovis-test - VALID

    Read the article

  • help with regex pattern

    - by noname
    i have multiple strings containing a link like: <A HREF="http://www.testings2">testings2</A> <A HREF="http://www.blabla">blabla</A> <A HREF="http://www.gowick">gowick</A> i want to use a regex pattern that gets the uri within the href. i could do like: /".*?"/ but then the "" will come along. is there a way to just get the uri within the HREF="" without using preg_replace function? thanks!

    Read the article

  • Javascript Regex to convert dot notation to bracket notation

    - by Tauren
    Consider this javascript: var joe = { name: "Joe Smith", location: { city: "Los Angeles", state: "California" } } var string = "{name} is currently in {location.city}, {location.state}"; var out = string.replace(/{([\w\.]+)}/g, function(wholematch,firstmatch) { return typeof values[firstmatch] !== 'undefined' ? values[firstmatch] : wholematch; }); This will output the following: Joe Smith is currently in {location.city}, {location.state} But I want to output the following: Joe Smith is currently in Los Angeles, California I'm looking for a good way to convert multiple levels of dot notation found between braces in the string into multiple parameters to be used with bracket notation, like this: values[first][second][third][etc] Essentially, for this example, I'm trying to figure out what regex string and function I would need to end up with the equivalent of: out = values[name] + " is currently in " + values["location"]["city"] + values["location"]["state"];

    Read the article

  • How to improve my Python regex syntax?

    - by FarmBoy
    I very new to Python, and fairly new to regex. (I have no Perl experience.) I am able to use regular expressions in a way that works, but I'm not sure that my code is particularly Pythonic or consise. For example, If I wanted to read in a text file and print out text that appears directly between the words 'foo' and 'bar' in each line (presuming this occurred one or zero times a line) I would write the following: fileList = open(inFile, 'r') pattern = re.compile(r'(foo)(.*)(bar)') for line in fileList: result = pattern.search(line) if (result != None): print result.groups()[1] Is there a better way? The if is necessary to avoid calling groups() on None. But I suspect there is a more concise way to obtain the matching String when there is one, without throwing errors when there isn't. I'm not hoping for Perl-like unreadability. I just want to accomplish this common task in the commonest and simplest way.

    Read the article

  • How to make regex variables to capture of routes

    - by Zephiro
    anyone can help me with this problem. example $uri = '/username/carlos'; => $routes[] = '/username/@name'; @name convert in variable $name capturing string "carlos" $routes[] = '/list/edit/@id:[0-9]{3}'; $routes[] = '/username/@name'; $routes[] = '/archive/*'; $routes[] = '/'; $uri = '/username/carlos'; foreach ( $routes as $pattern ) { if ( preg_match( '#^' . preg_replace( '#(?:{{)?@(\w+\b)(?:}})?#i', '(?P<\1>[\w\-\.!~\*\'"(),\s]+)', str_replace( '\*', '(.*)', preg_quote( $pattern, '/' ) ) ) . '\/?$#i', $uri, $matchs ) ) { //how to make regex for this to work : echo $name; // carlos =>$uri = '/username/carlos'; or matt => $uri = '/username/matt'; } } thanks for reading

    Read the article

  • RegEx: Split String at Capitalized Letters and Non-capitalized letters to Create Small Cap Fonts

    - by Otaku
    So i've purposefully stayed away from RegEx as just looking at it kills me...ugh. But now I need it and could really use some help to do this in .NET (C# or VB.NET). I need to split a string based on capitalization or lack thereof. For example: I'm not upPercase "I" "'m not up" "P" "ercase" or FBI Agent Winters "FBI A" "gent " "W" "inters" The reason I'm doing this is to manually create small caps, in which non-capitalized strings will be sent to uppercase and their font size made 80% of the original font size. Appreciate any help that could be provided here.

    Read the article

  • RegEx to extract all HTML tag attributes including inline JavaScript

    - by Mike
    I found this useful regex code here while looking to parse HTML tag attributes: (\S+)=["']?((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']? It works great, but it's missing one key element that I need. Some attributes are event triggers that have inline Javascript code in them like this: onclick="doSomething(this, 'foo', 'bar');return false;" Or: onclick='doSomething(this, "foo", "bar");return false;' I can't figure out how to get the original expression to not count the quotes from the JS (single or double) while it's nested inside the set of quotes that contain the attribute's value.

    Read the article

  • Add / remove a port number to/from a URL with REGEX in PHP

    - by SuperDuck
    Hello guys, I've searched but was unable to find an existing regex function. Has anybody done this before? I wish to add a port number, or remove a potantially existing one from a url in php. To use in some functions which translate a given url to the secure one, unsecure one, etc. Now I need a second SSL secured site on the server so I need to dynamically add a port number while converting http to https, and remove any port number while converting from https to http. Thanks, Duck

    Read the article

  • Regex to match 2 things in 1 HTML file

    - by CyberK
    Hi, I have a HTML file which contains the following: <img src="MATCH1" bla="blabla"> <something:else bla="blabla" bla="bla"><something:else2 something="something"> <something image="MATCH2" bla="abc"> Now I need a regex to match both MATCH1 and MATCH2 Also the HTML contains multiple parts like this, so it can be in the HTML 1, 2, 3 of x times.. When I say: <img\s*src="(.*?)".*?<something\s*image="(.*?)" It doesn't match it. What am I missing here? Thanks in advance!

    Read the article

  • replacing strings with regex in javascript

    - by koko
    Hi, regex is bugging me right now. I simply want to replace the range=100 in a string like var string = '...commonstringblabla&range=100&stringandsoon...'; with ...commonstringblabla&range=400&stringandsoon... I successfully matched the "range=100"-part with alert( string.match(/range=100/) ); But when I try to replace it string.replace(/range=100/, 'range=400'); nothing happens, the string still has the range=100 in it... I don't get it, please help.

    Read the article

  • RegEx for a date format

    - by Ivan
    Say I have a string like this: 07-MAY-07 Hello World 07-MAY-07 Hello Again So the pattern is, DD-MMM-YY, where MMM is the three letter format for a month. What Regular Expression will break up this string into: 07-MAY-07 Hello World 07-MAY-07 Hello Again Using Jason's code below modified for C#, string input = @"07-MAY-07 Hello World 07-MAY-07 Hello Again"; string pattern = @"(\d{2}-[A-Z]{3}-\d{2}\s)(\D*|\s)"; string[] results = Regex.Split(input, pattern); results.Dump(); Console.WriteLine("Length = {0}", results.Count()); foreach (string split in results) { Console.WriteLine("'{0}'", split); Console.WriteLine(); } I get embedded blank lines? Length = 7 '' '07-MAY-07 ' 'Hello World ' '' '07-MAY-07 ' 'Hello Again' '' I don't even understand why I am getting the blank lines...?

    Read the article

  • RegEx - Match optional groups

    - by Maurizio
    I know RE is not the best way to scrape HTMLs, but this is it... I have some something like: <td> Writing: <a href="creator.php?c=CCh">Carlo Chendi</a> Art: <a href="creator.php?c=LBo">Luciano Bottaro</a> </td> And I need to match the Writing and Art parts. But it is not said they're there and there could be other parts like Ink and Pencils... How do i do this ? I need to use pure Regex, no additional Python libs... Thanks !

    Read the article

  • Regex & BBCode - Perfecting Nested Quote

    - by Moe
    Hey there, I'm working on some BBcode for my website. I've managed to get most of the codes working perfectly, however the [QUOTE] tag is giving me some grief. When I get something like this: [QUOTE=1] [QUOTE=2] This is a quote from someone else [/QUOTE] This is someone else quoting someone else [/QUOTE] It will return: > 1 said: [QUOTE=2]This is a quote from > someone else This is someone else quoting someone else[/QUOTE] So what is happening is the [/quote] from the nested quote is closing the quote block. The Regex I am using is: "[quote=(.*?)\](.*?)\[/quote\]'is" How can I make it so nested Quotes will appear properly? Thank you.

    Read the article

  • Regex to detect a proper permalink?

    - by Fedor
    These permalinks above are rerouted to my page: page.php?permalink=events/foo page.php?permalink=events/foo/ page.php?permalink=ru/events/foo page.php?permalink=ru/events/foo/ The events is dynamic, it could be specials or packages. My dilemma is basically; I need to detect an empty link in order so I can feed a robots no index meta tag in the case of: page.php?permalink=events page.php?permalink=events/ page.php?permalink=ru/events/ page.php?permalink=ru/events I can't use a simple pattern such as [a-zA-Z]+\/?(.+)/ since it won't work on the i18n permalinks. What regex could I use which would detect this, using $_GET['permalink'] as the reference to the permalinks? And avoid false positives? Update: Empty link means there's no fragment after the "events/" part. These are empty: page.php?permalink=events page.php?permalink=events/ page.php?permalink=ru/events/ page.php?permalink=ru/events

    Read the article

  • Using a regex to determine domain using JavaScript

    - by jerome
    Hi All, If, as here at work, we have test, staging and production environments, such as: http://test.my-happy-work.com http://staging.my-happy-work.com http://www.my-happy-work.com I am writing some javascript that will redirect the browser to a url such as: http://[environment].my-happy-work.com/my-happy-video I need to be able to determine the current environment that we are in. There is the possibility that I will currently be at a url such as: http://[environment].my-happy-work.com/my-happy-path/my-happy-resource I want to be able to grab the window.location but strip it of everything but: http://[environment].my-happy-work.com And then append to that string + "/" + "my-happy-video". I am not skilled with regex, but I suppose there would be a way to parse the window.location up to the ".com" Thoughts? Thanks!

    Read the article

  • regex for shortforms

    - by Sourabh
    I need a regex (JavaScript) which will extract shortforms from a string for example from below string Hibbs' essays in progress include "Anselm's Sacramental Imagination," "W.E.B. DuBois and Socratic Questioning," and "Everything That Rises Must Converge: Aquinas's Theological Re-formation of the Cardinal Virtues." it will match "W.E.B." so the condition is it should have DOTs to seperate the letters or from Marcih J. Robert II. Distinguished Professor of Electrical & Computer Engineering. Ph.D. (1977) Texas Tech University, B.S./M.S. Rose-Hulman Institute of Technology (1972/1973). Ph.D. B.S. M.S. will match Thanks

    Read the article

< Previous Page | 19 20 21 22 23 24 25 26 27 28 29 30  | Next Page >