Questions tagged [regex]

Regex (or regexp) is known as regular expression matching of patterns, strings or characters in, for example, a large text file. Questions should be tagged as such whatever the programming language involved and the tag can also apply to command-line or graphical programs that have regex plugins or some regex capability.

The syntax of regular expressions varies between programming languages, and the formulations developed can vary from the simple to the ultra-complex. Probably the simplest form of regex is what takes place in the shell when a search is performed, for example for files matching *.jpg, and all jpgs within the current working directory are found.

At this site the different types of regex are introduced; Basic Regular Expressions (BRE), Extended Regular Expressions (ERE) and Perl-compatible Regular Expressions (PCRE). However, different programs will have different regular expression capabilities. Shell programs such as grep and sed have special switches that enable them to use more advanced regular expressions; grep, for example, can use ERE with the -E switch and PCRE with the -P switch.

A very useful general introduction to regex and its use in the shell is in chapter 20 of Linux Command and Perl regular expressions are documented in great detail in the official documentation.

309 questions
5
votes
5 answers

Exclude directories from inotifywait

Doing an inotifywait to watch a directory, and trying to exclude all subdirectories from being watched while not excluding the files. inotifywait -r -q --exclude dir/ What to put in ? Manual for inotifywait specifies: --exclude…
Sqerstet
  • 701
  • 1
  • 8
  • 22
4
votes
2 answers

Extracting names from filename in Bash

I have a directory filled with thousands of files in the format LastnameFirstnameYYYYMMDD.pdf. The last and first name will always been in title case. I'd like to extract the last name so I can move these files to a directory structure of {first…
2
votes
1 answer

Regular expression to pull db table names from .sql files

I'm looking to search my directory of sql queries and for the most prevalent database tables in all of the files. To do so, I'm hoping to use grep to isolate these names but I can't quite figure out the regular expression to pull just the table…
2
votes
2 answers

patterns symbol in regular expression

I am new to regex, Can anyone explain for me the patterns: (|) (method="[a-zA-Z]*|METHOD="[a-zA-Z]*)
Vendetta
  • 151
2
votes
3 answers

Searching through output of more command

When searching through the output of more command how can I search for a phrase that includes spaces in between? When I search for a phrase like "typedef struct audiodev" it doesn't find the phrase in the file and I'm assuming this is because I need…
A1A2A3A4
  • 153
  • 1
  • 1
  • 5
2
votes
2 answers

Help with regular expression

Trying to build a regular expression that will match all strings that begin with word "med-" and end with ".opol.nei.com" like this one med-fe3-ua-kiol-33.opol.nei.com
2
votes
1 answer

How to filter a regex (exclude special characters)

Let's say that I need to filter all my files' names that don't include special characters. ASDA123fasf - would pass asasdasd*dasd - wouldn't pass
1
vote
1 answer

Regex to find files with certain number of underscores

I have two files: AAAAA_AAAA_BBBBBBBB_SSSSSS AAAAA_BBBBBBBB_SSSSSS I want only the file with two underscores be shown. I used: ls -1 ^?*_?*_?*$ I got: ls: ?*_?*_?*$: No such file or directory Why? And what can be a solution?
Josef Klimuk
  • 1,596
1
vote
3 answers

Missing delimiter "^" error while using regex to match 3-character words in a string

I am having trouble coming up with the proper regular expression to match 3-character strings. I have this string: asdasa asdas asdhhgfh dfgdfdasa ttte aa1 asasda aa2 I'm trying to use regex, but can't manage to craft the proper regular expression…
1
vote
1 answer

use of patterns symbol in regular expression

I am new to regex, Can anyone explain for me the patterns: [a-fA-F\d]{30} [\d\w] [-+_~.\d\w] [-\d\w]{0,253}
Vendetta
  • 151
1
vote
1 answer

how to parse watch command output to last 5 digits?

From the command watch -n1 "ifconfig eth0 | grep GiB". I have output given below, Now i just want the last 5 digits before (GiB). I wrote an regex for it, and it seems to work (\d{1,4})(?!.*\d)\sGiB The only problem is that i cannot use it with…
asadz
  • 167
1
vote
1 answer

How to refer to the 'found' result in Regex

Regex will find matches that satisfy the expression but are different. How to you refer to the result instance in order to append to each instance? I have created a text file by copy/paste from a website that does not provide any sort of file…
1
vote
0 answers

Is it possible to restrict a regular expression to a given number of characters or perform two logically AND connected tests in one regex?

I have to split a table into columns. The texts in two neighboring columns each match the expression (\S+\s+)+\s*. But sometimes, one column gets a bit larger than it should and then there is only one space at the end of the element in the 1st…
0
votes
1 answer

Regex to match Oxford or serial comma

I learned one Regex to be able to detect sentences with the Oxford comma and sentences without. For example for a sentence like the below I went to the store and bought eggs, milk, apples, butter, and bread. I will use (?:\w+,\s+){2,}and\s+\w+ …
0
votes
0 answers

What are the regex capabilities of FocusWriter

I am trying to remove line breaks using regex \n in FocusWriter, but it isn't recognised. Does anyone know which regex capabilities FocusWriter has? I know that [1,2,3] will match 1 or 2 or 3
1
2