Regex

Here lies all the regular expressions that I found useful

regex101: build, test, and debug regex

get anything to the right of --

/(?<=\-\-).*/

get anything to the left of --

/^.*(?=\-\-)/

get anything between [ ]

/(?<=\[).*(?=\])/

finds string between ]( & ) → used to find string between ]( & ) i.e. [link](http://this.com)

/(?<=\]\().*(?=\))/g

replace any special characters that OS's don't like

STRING.replace(/[&#\@\!, +()$~%'":*?<>{}]/g, '_')

Only alphabet characters are allowed for this field. NO spaces

/^[aA-zZ]+$/, 

phone number validation

/^([+]?\d{1,2}[-\s]?|)\d{3}[-\s]?\d{3}[-\s]?\d{4}$/

Standard Password

/^(?=.*[A-Z])(?=.*[!@#{{CODE_BLOCK_7}}*])(?=.*[0-9])(?=.*[a-z].*[a-z].*[a-z]).{8,40}$/
^                         Start anchor
(?=.*[A-Z].*[A-Z])        Ensure string has two uppercase letters.
(?=.*[!@#{{CODE_BLOCK_8}}*])            Ensure string has one special case letter.
(?=.*[0-9].*[0-9])        Ensure string has two digits.
(?=.*[a-z].*[a-z].*[a-z]) Ensure string has three lowercase letters.
.{8}                      Ensure string is of length 8.
$                         End anchor.

Find a every line that starts with (with wildcard). Useful with iTunes XML Playlist to m3u Converter

# don't forget to excape any slashes \/
^\/Volumes\/edata\/iMusicLibrary\/.*$

# select any line that starts with "#EXTINF:" could have any number after colon, and ends with comma.
# examples that are removed: "#EXTINF:177,", "#EXTINF:246,", "#EXTINF:192,"
^#EXTINF:.*?,

get file name extension

let file = url.match(/?<=\.)[^.\\/:*?"<>|\r\n]+$/)
console.log(file[0])
	

remove file extension from path

filePath.replace(/\.[^/.]+$/, '')
Find and Replace string between and but starts with [[http
const regex = \[\[(http.*?)\]\]
// replace string
[link]($1)
// `---
{"dg-publish":true,"permalink":"/developer/Regex/","created":"2024-02-29T22:19:55.735-06:00","updated":"2024-03-01T00:21:37.000-06:00"}
---



Here lies all the regular expressions that I found useful

[regex101: build, test, and debug regex](https://regex101.com/)

get anything to the right of `--`
```js
/(?<=\-\-).*/

get anything to the left of --

/^.*(?=\-\-)/

get anything between [ ]

/(?<=\[).*(?=\])/

finds string between ]( & ) → used to find string between ]( & ) i.e. [link](http://this.com)

/(?<=\]\().*(?=\))/g

replace any special characters that OS's don't like

STRING.replace(/[&#\@\!, +()$~%'":*?<>{}]/g, '_')

Only alphabet characters are allowed for this field. NO spaces

/^[aA-zZ]+$/, 

phone number validation

/^([+]?\d{1,2}[-\s]?|)\d{3}[-\s]?\d{3}[-\s]?\d{4}$/

Standard Password

/^(?=.*[A-Z])(?=.*[!@#{{CODE_BLOCK_7}}*])(?=.*[0-9])(?=.*[a-z].*[a-z].*[a-z]).{8,40}$/
^                         Start anchor
(?=.*[A-Z].*[A-Z])        Ensure string has two uppercase letters.
(?=.*[!@#{{CODE_BLOCK_8}}*])            Ensure string has one special case letter.
(?=.*[0-9].*[0-9])        Ensure string has two digits.
(?=.*[a-z].*[a-z].*[a-z]) Ensure string has three lowercase letters.
.{8}                      Ensure string is of length 8.
$                         End anchor.

Find a every line that starts with (with wildcard). Useful with iTunes XML Playlist to m3u Converter

# don't forget to excape any slashes \/
^\/Volumes\/edata\/iMusicLibrary\/.*$

# select any line that starts with "#EXTINF:" could have any number after colon, and ends with comma.
# examples that are removed: "#EXTINF:177,", "#EXTINF:246,", "#EXTINF:192,"
^#EXTINF:.*?,

get file name extension

let file = url.match(/?<=\.)[^.\\/:*?"<>|\r\n]+$/)
console.log(file[0])
	

remove file extension from path

filePath.replace(/\.[^/.]+$/, '')
Find and Replace string between and but starts with [[http
means the output variable

find replace string between `[`and `](`
```js
const regex = \[(.*)\]\((.*)\)

replace string -->  $1 

HTML Input Pattern Attribute

An <input> element with type="email" that must be in the following order: characters@characters.domain (characters followed by an @ sign, followed by more characters, and then a "."

After the "." sign, add at least 2 letters from a to z:

<form action="/action_page.php">  
  <label for="email">Email:</label>  
  <input type="email" id="email" name="email"  
  pattern="[a-z0-9._%+\-]+@[a-z0-9.\-]+\.[a-z]{2,}$">  
  <input type="submit">  
</form>

Credits