# Regex in Golang

Regular expression a.k.a Regex is a sequence of characters that define a search pattern

### Cheat sheet

Regexp | Meaning |
---|---|

xy | x followed by y |

x|y | x or y, prefer x |

xy|z | same as (xy)|z |

xy* | same as x(y*) |

^ | matches the beginning of the string |

$ | matches the end of the string |

. | matches any single character except line break |

* | matches the preceding expression zero or more times |

`\d` | any single digit character |

`w` | any word (alphanumeric & underscore) [0-9A-Za-z_] |

`W` | any character that is not a word [^0-9A-Za-z_] |

`D` | any character that is not a digit |

`s` | whitespace |

`S` | a non-whitespace character: [^ ] |

[abc] | any single character from the character within the brackets |

[a-z] | character set range from a to z |

[abc]+ | one or more characters from the set |

[^a-z] | match anything without the character range |

+ | one or more |

{3} | exactly 3 times |

{2,4} | 2 to 4 times |

{3,} | 3 or more times |

* | zero or more times |

? | once or none |

x* | zero or more x, prefer more |

x*? | prefer fewer (non-greedy) |

x+ | one or more x, prefer more |

x+? | prefer fewer (non-greedy) |

x? | zero or one x, prefer one |

x?? | prefer zero |

x{n} | exactly n x |

i | case-insensitive |

m | let ^ and $ match begin/end line in addition to begin/end text (multi-line mode) |

s | let . match (single-line mode) |