How to make regex in Objective-C

I am always confused by the Regex format, how they work, and how to make Regex as per my requirement. I just copy some common Regex formats and paste into my project, but obviously we cannot find each Regex format according to our requirement. Therefore, I would like to learn about Regex.

I only do this from my guess after running the code over and over, but still I don’t know so much about this Regex

NSString *regexNumber = @"[123456789][0-9]{0}([0-9]{1})?";

This comparison Age, according to this age, should start from 1-9, at least 1 digit, at most 2 digits and only numeric.

Now I want to make a Regex for Name - (exp - vakul, Vakul, vakul saini, Vakul Saini, vakul Saini, Vakul saini, etc.), Email , Phone number , String only , Birthday , URL . But I do not want to copy and paste, I want to find out how they work, and how to create your own Regex.

+5
source share
2 answers

A regular expression is a text pattern consisting of a combination of alphanumeric characters and special characters known as metacharacters

Metacharacters:

\ | ( ) [ { ^ $ * + ? . < >

. ---- This is instead a special metacharacter that matches any character.

* ---- * .

+ ---- + *, .

? ----

{m,n} ---- m n . {1,5} 1 5

^ ---- ,

$ --- ,

<> --- . . , abc

, , : () (

| ---

[ and ] --- . , , , . - ^, . . [a-z]

, , .

+7
0

All Articles