regex

  • 12 Nov

    Regular expressions reference guide

    Regular expressions reference guide

    ANCHORS

    ^         Match the start of a string
    $         Match the end of a string
    \b        Match a word boundary
    \B        Match a non-word boundary

    ANCHORS Examples

    ^Hello    Matches "Hello world" but not "Say Hello"
    world$    Matches "Hello world" but not "world peace"
    \bcat\b   Matches "cat" in "the cat sat" but not in "category"
    \Bcat     Matches "cat" in "category" but not in "the cat"
    \bcat     Matches "cat" at word start: "cat" and "category"
    cat\b     Matches "cat" at word end: "cat" and "tomcat"

    CHARACTER SETS

    [xyz]     Match any of x, y or z
    [^xyz]    Match anything except x, y or z
    [0-9]     Match any digit
    [a-z]     Match any lowercase letter

    CHARACTER SETS Examples

    [aeiou]   Matches any vowel
    [^aeiou]  Matches any consonant (non-vowel)
    [0-9]     Matches "5" in "Hello5"
    [a-zA-Z]  Matches any letter (upper or lower)
    [a-z0-9]  Matches any lowercase letter or digit
    gr[ae]y   Matches both "gray" and "grey"
    [^0-9]    Matches any non-digit character

    ESCAPE CHARACTERS

    \.        Matches a literal period/dot character
    \d        Matches any digit (0-9)
    \s        Matches any whitespace (space, tab, newline)
    \w        Matches any word character (a-z, A-Z, 0-9, _)
    \D        Matches any non-digit
    \S        Matches any non-whitespace
    \W        Matches any non-word character

    ESCAPE CHARACTERS Examples

    192\.168\.1\.1   Matches IP address (dots are literal)
    \d{3}            Matches "123" in "Room 123"
    Hello\sWorld     Matches "Hello World" or "Hello World"
    \w+              Matches "hello", "test123", "my_var"
    \d+\.\d+         Matches decimal numbers like "3.14" or "99.99"
    \w+@\w+\.\w+     Matches simple email pattern

    FLAGS / MODIFIERS

    i         Case-insensitive matching
    g         Global match (find all matches)
    m         Multiline mode (^ and $ match line breaks)
    s         Dotall mode (. matches newline)

    FLAGS / MODIFIERS Examples

    Case-insensitive (i):
    /hello/ Matches only “hello”
    /hello/i Matches “hello”, “Hello”, “HELLO”, “HeLLo”

    Global (g):
    /cat/ Matches first “cat” in “cat and cat”
    /cat/g Matches both “cat” instances

    Multiline (m):
    Text: “Line 1\nLine 2\nLine 3”
    /^Line/ Matches only first “Line”
    /^Line/m Matches all three “Line” at start of each line
    /\d$/m Matches digit at end of each line

    Dotall (s):
    Text: “Hello\nWorld”
    /Hello.World/ No match (. doesn’t match \n)
    /Hello.World/s Matches (. now matches \n)

    Combined flags:
    /test/gi Case-insensitive AND global
    /^start/mi Multiline AND case-insensitive

    GREEDY vs LAZY

    *         Greedy: match as much as possible
    *?        Lazy: match as little as possible
    +         Greedy
    +?        Lazy
    ?         Greedy
    ??        Lazy
    {n,m}     Greedy
    {n,m}?    Lazy

    GROUPS

    (xyz)     Match 'xyz' as group
    (x|y)     Match 'x' or 'y'
    (?=xyz)   Match succeeds only if followed by xyz
    (?!xyz)   Match succeeds only if not followed by xyz

    GROUPS Examples

    (cat|dog)        Matches "cat" or "dog"
    (\d{3})-(\d{4})  Matches "555-1234" (captures area code and number separately)
    (https?://)?     Matches optional "http://" or "https://"
    test(?=ing)      Matches "test" in "testing" but not in "tester"
    test(?!ing)      Matches "test" in "tester" but not in "testing"
    \d+(?=px)        Matches "10" and "20" in "10px 15em 20px"
    \$\d+(?!\.)      Matches "$50" but not "$50.99" (whole dollars only)

    GROUPS References (BACKREFENCES)

    \1        Reference to first captured group
    \2        Reference to second captured group

    SPECIAL CHARACTERS

    \t        Tab character
    \n        Newline
    \r        Carriage return
    \\        Literal backslash
    \*        Literal asterisk
    \+        Literal plus
    \?        Literal question mark

    SPECIAL CHARACTERS Examples

    \t           Matches tab in "Hello\tWorld"
    \n           Matches newline in multi-line text
    Price: \$50  Matches "Price: $50" (literal dollar sign)
    C:\\Users    Matches "C:\Users" (literal backslash)

    QUANTIFIERS

    ?         Match 0 or 1 time (optional)
    *         Match 0 or more times
    +         Match 1 or more times (at least once)
    {n}       Match exactly n times
    {n,}      Match n or more times
    {n,m}     Match between n and m times

    QUANTIFIERS Examples

    a?        Matches "" or "a"
    a*        Matches "", "a", "aa", "aaa", etc.
    a+        Matches "a", "aa", "aaa", etc. (but not empty)
    a{3}      Matches exactly "aaa"
    a{2,}     Matches "aa", "aaa", "aaaa", etc.
    a{2,4}    Matches "aa", "aaa", or "aaaa"

    If you need any help about this ‘Regular expressions reference guide’, please let us know.

    Best Regards,

    Limagito Team

    #regex #managedfiletransfer #filetransfer #filemanagement

    By Limagito-Team Rename ,
  • 06 Jul

    Having 10 or more groups and want to reference group 1 in RegEx

    Having 10 or more groups and want to reference group 1 in RegEx

    Q: This regex rename is under the unzip…

    My intent is to fix the lack of a leading zero in the MM field of the file name but limagito is seeing it as capture group 10, not capture group 1 with a zero after it.
    Escaping the zero didn’t work either. Is there something else i could have done?
    I eventually hard coded the 2025, because hopefully this is a 1 off error anyway.

    limagito file mover reference group 1 in RegEx

    A: You’ve identified a classic regex gotcha! When you have 10 or more groups and want to reference group 1 followed by a literal “0”, the regex engine interprets `\10` as group 10 instead of group 1 + “0”.

    Here is a solution to solve this: Use \g<n> syntax (most regex flavors)
    # Instead of: \10
    # Use: \g<1>0

    If you need any help with this ‘reference group 1 in RegEx’ question, please let us know.

    Best Regards,

    Limagito Team

    #regex #managedfiletransfer #filetransfer #filemanagement

    By Limagito-Team Rename
  • 08 Jun

    How to rename a file using its parent folder name

    How to rename a file using its parent folder name

    Q: When working with Limagito, we were wondering if you had recommendations on how to handle this scenario.

    1. We would like to transfer files from a directory lets call it E:\Orignal Location. I have two folders and files under this directory below.
      • Under E:\Orignal Location\UNIT_1_4.1.2025\history.xml
      • Under E:\Orignal Location\UNIT_2_5.1.2025\history.xml
    2. We would like to rename the history.xml to the parent folder name, highlighted above, while moving it to final file location E:\Final Location
    3. The file result we are looking for is for two files in the location  E:\Final Location:
      • UNIT_1_4.1.2025.xml
      • UNIT_2_5.1.2025.xml

    How would you recommend configuring, or is it possible to configure the renaming since the value we want to rename is the parent name, while also moving the file to a new location with Limagito.

    A: We did a test with pdf files instead of xml, but the result would be the same.

    In your case,  E:\Orignal Location\ would be the WIN Source

    Our Directory Filter setup:

    limagito file mover directory filter option

    limagito file mover directory setup

    Destination Setup:

    limagito file mover destination setup

    limagito file mover destination options

    limagito file mover Windows folder as destination

    Please uncheck ‘Create Subdir’ because all files should go to the same folder:

    limagito file mover destination file and directory options

    Enable ‘Rename Files during Copy/Move’

    limagito file mover destination file rename option

    – Add the following file renaming setup:
    RegEx:  (.*)\.(.*)
    Replacement:  %SFS.\2

    limagito file mover destination file rename setup

    – Alternative file renaming setup when you have multiple levels of subfolders:

    • %SFS:?=?: parameter option was added recently
      • %SFS:0=1:
        • 0 > start at the end of the subfolders(s) Var %SFS > %SFS = Source File Subfolder(s)
        • 1 > use the last subfolder part only
    RegEx:  (.*)\.(.*)
    Replacement:  %SFS:0=1:.\2

    limagito file mover file renaming setup

    – RunTime Log result:

    limagito file mover runtime log result

    If you need any help with this question, please let us know.

    Best Regards,

    Limagito Team

    #managedfiletransfer #filetransfer #filemanagement

    By Limagito-Team How-to Rename , ,
1 2
SEARCH