Skip to content

Instantly share code, notes, and snippets.

@rosvik
Last active May 19, 2019 11:04
Show Gist options
  • Select an option

  • Save rosvik/7fa0ca718376a85b49cd983c2dfca0d3 to your computer and use it in GitHub Desktop.

Select an option

Save rosvik/7fa0ca718376a85b49cd983c2dfca0d3 to your computer and use it in GitHub Desktop.
Regex snippets

https://regex101.com/r/nZEH9j/2

Regex:

(?:\n[\h]*@|^[\h]*@)\K([0-9]+)(?=[\s]*\n|[\s]*$)|(?<=[\h\n,]@)([0-9]+)(?=[\h\n,.-]|$)|(?<=[\s,]@|^@)\K([a-zA-ZæøåÆØÅ_0-9]*[a-zA-ZæøåÆØÅ_]+[a-zA-ZæøåÆØÅ_0-9]*+)(?=[\s,]|[-.,:]*[\s]|[-.,:]*$)

Test string:

  @ab.
# ^ match at start of string


# GROUP 1
@0123456789
@9412334
 @00000  
@999
 @123
    @123

# GROUP 2
,@123
@123,@123,@123
asdasd,@4782,asdada
@31, @2312, @1231
@123 @123 @1234567890
@123.-, 
@123.

# GROUP 3
@abdefghijklmnopqrstuæøå
@ABCDEFGÆØÅ
@123abc
@abc123
@123abc123
@abc.
@abc-
@abc:

# NO MATCH
@
.@412
-@634
@5234;
@4234@
@@1231
[email protected]
test@example
@asd@asd
asd@as-_d
@asd.@asd.@asd
@asd-d 
@ads.com
@ads-_
@asd^
@asdf
@asdasd🔥

Loreæøåm ipasdæøåsumæø dolor sit amet, consectetur adipisicing elit, sed do eiusmod @1234567890 @1 @0 tempor incididunt ut labore @1æøåÆØÅ123et0 dolore magna aliqua. Ut enim ad minim @veniam, @quis @nostrud @123 exercitation ullamco laboris nisi ut aliquip ex ea @commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit æøå esse cillum dolore @asd,@asd,@asd eu fugiat nulla [email protected] pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 


# v Match at end of string
@ab.

@123

https://regex101.com/r/yNaEP6/2

Regex:

([#]+)[ \t]+([\S]+[^\n]+)

Test string:

Match
=====
# 	 header with spaces👍
# 🔥123
# This is 🔥
# header
#	dasdadsa
## dasd
### asdas
#### asdasd


No match
========
asdasdasd
# 🔥
#
#noheader
#		

v Match at end of string
 # adsasd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment