logo
down
shadow

Regex with multiple optional groups


Regex with multiple optional groups

By : user2954617
Date : November 22 2020, 10:31 AM
it fixes the issue I've had a search but I can't find a working solution to this. I'm working on a regex for the header formatting for Excel files. These use &-commands for formatting headers and footers, then left, centre and right headers are simply joined together: , Try
code :
^(?:.*?(?P<left>&L.[^&]*))?(?:.*?(?P<center>&C.[^&]*))?(?:.*?(?P<right>&R.[^&]*))?.*$
(?:
    .*? # consume any preceding text
    (?P<left> # then capture...
        &L # "&L" literally
        . # the character after that
        [^&]* # and then everything up to the next "&" character
    )
)? # and make the whole thing optional.
(?P<left>&L.+?)?(?P<center>&C.+?)?(?P<right>&R.+?)?$


Share : facebook icon twitter icon
How can I have multiple optional groups in RegEx

How can I have multiple optional groups in RegEx


By : user3364324
Date : March 29 2020, 07:55 AM
I wish did fix the issue. (Abbreviated) regular expression to match multiple options, of which the whole group is optional:
code :
( -(pause|start|download [^ ]+))?
-pause
-start
-download filename
// matches nothing too
-pause -start
python regex multiple optional capture groups

python regex multiple optional capture groups


By : matthew brookes
Date : March 29 2020, 07:55 AM
I hope this helps you . Regex is not the best tool for parsing in this case, I suppose there are tool exactly for that. However with given examples, you can try this:
code :
<a title="(.+?)\s?((Vol(\d+))?\s?\.?(Ch.(\d+)))?"\shref="(.+)">
Java Regex to Parse a Path Into Multiple Optional Groups

Java Regex to Parse a Path Into Multiple Optional Groups


By : yinswenti
Date : March 29 2020, 07:55 AM
will help you I am trying to split this type string using a Java Regex: , The following regex will match what you defined:
code :
 ^(/api)?(/v\d+)?(/[^/]+(?:/[^/]+)*?)??(?:(/category[12])(/.*)?)?$
String text = "/api/v2/client/domain/category2/id";
String pattern = "^(/api)?(/v\\d+)?(/[^/]+(?:/[^/]+)*?)??(?:(/category[12])(/.*)?)?$";
Pattern regex = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
Matcher m = regex.matcher(text);

while (m.find())
{
    System.out.println("api: " + m.group(1) + 
                       "\nversion: " + m.group(2) +
                       "\nclient: " + m.group(3) +
                       "\ncategory: " + m.group(4) +
                       "\nextra: " + m.group(5));
}
api: /api
version: /v2
client: /client/domain
category: /category2
extra: /id
Regex: Capture multiple optional groups with a single match

Regex: Capture multiple optional groups with a single match


By : J. Doe
Date : March 29 2020, 07:55 AM
this one helps. As Wiktor correctly states, there is no way to do this with a single regex. Here is a simple function that implements a 3-regex solution:
code :
function get_time_parts(text) {
    var s, m, h;
    // Seconds part: Either  "s", "sec", "secs" "second" or "seconds".
    s = text.match(/\b(\d+)\s*s(?:ec(?:ond)?s?)?\b/i);
    s = s ? s[1] : undefined;
    // Minutes part: Either "m", "min", "mins" "minute" or "minutes".
    m = text.match(/\b(\d+)\s*m(?:in(?:ute)?s?)?\b/i);
    m = m ? m[1] : undefined;
    // Hours part: Either "h", "hr", "hrs" "hour" or "hours".
    h = text.match(/\b(\d+)\s*h(?:rs?|ours?)?\b/i);
    h = h ? h[1] : undefined;
    return (s || m || h) ? [s, m, h] : null;
}
RegEx to match multiple optional groups of elements (javascript)

RegEx to match multiple optional groups of elements (javascript)


By : Robert Cate
Date : March 29 2020, 07:55 AM
To fix the issue you can do I need a regular expression to match the following kind of strings in Javascript: , This regular expression works for me:
Related Posts Related Posts :
  • Regex wheel size or digits after point
  • Replace number with repeated characters
  • Regex replace hexadecimal characters
  • Pasting character vectors, removing NA's and separators between NAs
  • Perl: basic perl regex parsing for word@word
  • %0 is not replaced by server name when used with Apache's ProxyPassMatch
  • Regular expression for two fields on JSON response - Jmeter
  • Adding to the requirejs optimizer fileExclusionRegExp
  • grep file with full contain string
  • merge two regular expressions in vs2010
  • Get substring up until the first question mark
  • Regular expression to match part of word
  • editing a JSON file with sed
  • R: RegEx for coordinates
  • Regex 5 digits number from Subject Line in MS Outlook
  • PERL: Matching multiple patterns
  • Extract location data using regex in R
  • Extracting Dates Using Regular Expression in R using grepl
  • Pseudo currency regex
  • Subject to permlink convertion in bash
  • Regular expression replace all occurrences of any word beginning with a certain substring
  • Umbraco 7 regex error: Value is invalid, it does not match the correct pattern
  • Regex using Vala and GLib
  • How to match multi-row data using regular expression R programming
  • Capitalize words in a bash variable using sed
  • Find last 30 occurrences of a string in a log file using Perl
  • How to use regex in bash for selecting a string between double quotes?
  • Golang to match dash(hyphen) character
  • How to express a escape sequence in regex. ("" -> ")
  • Regular Expression - Perl
  • Regex That Pulls Certain Bits From a String
  • Regex: This or that or none
  • Copying text from one line to another
  • find string that consists only of a certain set of characters
  • Sublime Text 3: How to change the notation from ``->cls`` to some macro?
  • VBScript Return an entire line when searching for a string
  • Unwind array of objects mongoDB
  • To delete the last character with regex
  • Understanding negative lookahead
  • How can I exclude a string if it ends in ".d.ts"?
  • Need help regarding forming a regular expression -xml
  • Using sed to replace string in file by using regex capture group
  • How to match a sequence of whitespaces with c++11 regex
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org