ﺪﻫﺩ ﯽﻣ ﻞﯿﮑﺸﺗ ﺍﺭ a ﻪﮐ ﺖﺳﺍ ﺎﻫﺮﺘﮐﺍﺭﺎﮐ ﺯﺍ ﯼﺍ ﻪﻟﺎﺒﻧﺩ ﻢﻈﻨﻣ ﺕﺭﺎﺒﻋ ﮏﯾ
ﺩﺮﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻦﺘﻣ ﯽﻨﯾﺰﮕﯾﺎﺟ ﻭ ﻦﺘﻣ ﯼﻮﺠﺘﺴﺟ ﯼﺍﺮﺑ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ ﻮﺠﺘﺴﺟ ﯼﻮﮕﻟﺍ
ﺪﻫﺩ ﯽﻣ ﻞﯿﮑﺸﺗ ﺍﺭ ﻮﺠﺘﺴﺟﮏﯾ ﻪﮐ ﺖﺳﺍ ﺎﻫﺮﺘﮐﺍﺭﺎﮐ ﺯﺍ ﯼﺍ ﻪﻟﺎﺒﻧﺩ ،ﻢﻈﻨﻣ ﺕﺭﺎﺒﻋ ﮏﯾ
.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺪﯿﻨﮐﯽﻣ ﻮﺠﺘﺴﺟ ﻪﭽﻧﺁ ﻒﯿﺻﻮﺗ ﯼﺍﺮﺑ ﻮﺠﺘﺴﺟ ﯼﻮﮕﻟﺍ ﻦﯾﺍ ﺯﺍ ﺪﯿﻧﺍﻮﺗﯽﻣ ،ﺪﯿﻨ
.ﺪﺷﺎﺑ ﺮﺗ ﻩﺪﯿﭽﯿﭘ ﯼﻮﮕﻟﺍ ﮏﯾ ﺎﯾ ﺪﺣﺍﻭ ﺮﺘﮐﺍﺭﺎﮐ ﮏﯾ ﺪﻧﺍﻮﺗ ﯽﻣ ﻢﻈﻨﻣ ﺕﺭﺎﺒﻋ ﮏﯾ
ﺩﺮﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻢﻈﻨﻣ ﺕﺍﺭﺎﺒﻋ ﺯﺍ ﻥﺍﻮﺗ ﯽﻣ ﻦﺘﻣ ﯼﻮﺠﺘﺴﺟ ﻉﺍﻮﻧﺍ ﻪﻤﻫ ﻡﺎﺠﻧﺍ ﯼﺍﺮﺑ
/pattern/modifiers;
/w3schools/i;
:ﻩﺪﺷ ﻩﺩﺍﺩ ﺢﯿﺿﻮﺗ ﻝﺎﺜﻣ
/w3schools/i ﺖﺳﺍ ﻢﻈﻨﻣ ﺕﺭﺎﺒﻋ ﮏﯾ.
w3schools (ﻮﺠﺘﺴﺟ ﺭﺩ ﻩﺩﺎﻔﺘﺳﺍ ﯼﺍﺮﺑ) ﺖﺳﺍ ﻮﮕﻟﺍ ﮏﯾ.
i ﺡﻼﺻﺍ ﮏﯾﺖﺳﺍ ﻩﺪﻨﻨﮐ (ﯽﻣ ﺮﯿﯿﻐﺗ ﯽﮔﺭﺰﺑ ﻪﺑ ﺍﺭ ﻮﺠﺘﺴﺟﺪﻫﺩ).
ﺩﻮﺷ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﻪﺘﺷﺭ ﻭﺩ ﺎﺑ ﺐﻠﻏﺍ ﻢﻈﻨﻣ ﺕﺍﺭﺎﺒﻋ ،ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ
ﮏﯾ ﯼﻮﺠﺘﺴﺟ ﯼﺍﺮﺑ ﺕﺭﺎﺒﻋ ﮏﯾ ﺯﺍ search()
ﺵﻭﺭ
ﻥﺁ ﺭﺩ ﻪﮐ ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﻪﺘﻓﺎﯾ ﺮﯿﯿﻐﺗ ﻪﺘﺷﺭ ﮏﯾ replace()
:ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﻖﺑﺎﻄﺗ ﺖﯿﻌﻗﻮﻣ ﻭ ﺪﻨﮐ ﯽﻣ ﻮﺠﺘﺴﺟ ﺺﺨﺸﻣ ﺭﺍﺪﻘﻣ ﮏﯾ ﯼﺍﺮﺑ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ :ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻪﺘﺷﺭ ﮏﯾ ﺭﺩ "W3schools" ﯼﻮﺠﺘﺴﺟ ﯼﺍﺮﺑ ﻪﺘﺷﺭ ﮏﯾ ﺯﺍ :ﺩﻮﺑ ﺪﻫﺍﻮﺧ n ﺭﺩ ﻪﺠﯿﺘﻧ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻪﺘﺷﺭ ﮏﯾ ﺭﺩ "w3schools" ﯼﺍﺮﺑ ﮒﺭﺰﺑ ﻑﻭﺮﺣ ﻥﻭﺪﺑ ﯼﻮﺠﺘﺴﺟ ﻡﺎﺠﻧﺍ ﯼﺍﺮﺑ ﯽﻟﻮﻤﻌﻣ ﺕﺭﺎ :ﺩﻮﺑ ﺪﻫﺍﻮﺧ n ﺭﺩ ﻪﺠﯿﺘﻧ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺪﻨﮐ ﯽﻣ ﻦﯾﺰﮕﯾﺎﺟ ﻪﺘﺷﺭ ﺭﺩ ﯼﺮﮕﯾﺩ ﺭﺍﺪﻘﻣ ﺎﺑ ﺍﺭ ﻩﺪﺷ ﺺﺨﺸﻣ ﺭﺍﺪﻘﻣ ﮏﯾ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﮏﭼﻮﮐ ﻭ ﮒﺭﺰﺑ ﻑﻭﺮﺣ ﻪﺑ ﺱﺎﺴﺣ ﺮﯿﻏ ﻢﻈﻨﻣ ﺕﺭﺎﺒﻋ ﮏﯾ ﺯﺍ W3Schools ﺎﺑ ﺖﻓﺎﺳﻭﺮﮑﯾﺎﻣ ﯽﻨ :ﺩﻮﺑ ﺪﻫﺍﻮﺧ res ﺭﺩ ﻪﺠﯿﺘﻧ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ ﺡﻼﺻﺍﻩﺪﻨﻨﮐﺎﻫ ﯽﻣ ﺍﺭﯽﻧﺎﻬﺟ ﯼﺎﻫﻮﺠﺘﺴﺟ ﻡﺎﺠﻧﺍ ﯼﺍﺮﺑ ﻥﺍﻮﺗﺩ ﻩﺪﻨﻨﮐﺮﯿﯿﻐﺗ: ﺕﺎﺤﯿﺿﻮﺗ: ﺪﯿﻫﺩ ﻡﺎﺠﻧﺍ ﮒﺭﺰﺑ ﻭ ﮏﭼﻮﮐ ﻑﻭﺮﺣ ﻪﺑ ﺖﯿﺳﺎﺴﺣ ﻥﻭﺪﺑ ﻖﯿﺒﻄﺗ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻩﺪﻨﻨﮐﺮﯿﯿﻐﺗ: ﺕﺎﺤﯿﺿﻮﺗ: (ﺪﯿﻨﮐ ﺍﺪﯿﭘ ﺍﺭ ﺩﺭﺍﻮﻣ ﻪﻤﻫ ،ﻪﻘﺑﺎﺴﻣ ﻦﯿﻟﻭﺍ ﺯﺍ ﺲﭘ ﻒﻗﻮﺗ ﯼﺎﺟ ﻪﺑ) ﯽﻧ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻩﺪﻨﻨﮐﺮﯿﯿﻐﺗ: ﺕﺎﺤﯿﺿﻮﺗ: ﺪﯿﻫﺩ ﻡﺎﺠﻧﺍ ﺍﺭ ﯽﻄﺧ ﺪﻨﭼ ﻖﯿﺒﻄﺗ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺖﮐﺍﺮﺑ ﻪﺴﯾﻮﻧ ﺯﺍ ﯽﻔﯿﻃ ﻦﺘﻓﺎﯾ ﯼﺍﺮﺑﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﺎﻫﺩﻮﺷ: ﻩﺪﻨﻨﮐﺮﯿﯿﻐﺗ: ﺕﺎﺤﯿﺿﻮﺗ: ﻪﺴﯾﻮﻧ ﺯﺍ ﮏﯾ ﺮﻫﺪﯿﻨﮐ ﺍﺪﯿﭘ ﺎﻫﺰﺘﻧﺍﺮﭘ ﻦﯿﺑ ﺍﺭ ﺎﻫ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻩﺪﻨﻨﮐﺮﯿﯿﻐﺗ: ﺕﺎﺤﯿﺿﻮﺗ: ﺪﯿﻨﮐ ﺍﺪﯿﭘ ﺍﺭ ﺎﻫﺰﺘﻧﺍﺮﭘ ﻦﯿﺑ ﻡﺎﻗﺭﺍ ﺯﺍ ﮏﯾ ﺮﻫ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻩﺪﻨﻨﮐﺮﯿﯿﻐﺗ: ﺕﺎﺤﯿﺿﻮﺗ: ﺪﯿﻨﮐ ﺍﺪﯿﭘ ﺍﺭ | ﺎﺑ ﻩﺪﺷ ﺍﺪﺟ ﯼﺎﻫ ﻪﻨﯾﺰﮔ ﺯﺍ ﮏﯾ ﺮﻫ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺎﻫﺮﺘﮐﺍﺩﺍﺮﻓ ﺪﻨﺘﺴﻫ ﺹﺎﺧ ﯼﺎﻨﻌﻣ ﺎﺑ ﯽﯾﺎﻫﺮﺘﮐﺍﺭﺎﮐ: ﻩﺪﻨﻨﮐﺮﯿﯿﻐﺗ: ﺕﺎﺤﯿﺿﻮﺗ: ﺪﯿﻨﮐ ﺍﺪﯿﭘ ﻢﻗﺭ ﮏﯾ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻩﺪﻨﻨﮐﺮﯿﯿﻐﺗ: ﺕﺎﺤﯿﺿﻮﺗ: ﺪﯿﻨﮐ ﺍﺪﯿﭘ ﯽﻟﺎﺧ ﯼﺎﻀﻓ ﻪﺴﯾﻮﻧ ﮏﯾ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻩﺪﻨﻨﮐﺮﯿﯿﻐﺗ: ﺕﺎﺤﯿﺿﻮﺗ: ﺪﯿﻨﮐ ﺍﺪﯿﭘ ﺖﻘﺑﺎﻄﻣ ﺩﺭﻮﻣ ﻦﯾﺍ ﺪﻨﻧﺎﻣ ﯼﺍ ﻪﻤﻠﮐ ﯼﺍﺪﺘﺑﺍ ﺭﺩ: \bWORD ﻪ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻩﺪﻨﻨﮐﺮﯿﯿﻐﺗ: ﺕﺎﺤﯿﺿﻮﺗ: ﻪﺴﯾﻮﻧ Unicode ﻝﺎﻤﯿﺳﺩ ﺍﺰﮕﻫ ﺩﺪﻋ ﻂﺳﻮﺗ ﻩﺪﺷ ﺺﺨﺸﻣ xxxx ﺪﯿﻨﮐ ﺍﺪﯿﭘ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﯽﻤﮐﺎﻫﺎﻤﻧ ﺖﯿﻤﮐﯽﻣ ﻒﯾﺮﻌﺗ ﺍﺭ ﺎﻫﺪﻨﻨﮐ: ﻩﺪﻨﻨﮐﺮﯿﯿﻐﺗ: ﺕﺎﺤﯿﺿﻮﺗ: ﻪﺘﺷﺭ ﺮﻫ ﺎﺑﮏﯾ ﻞﻗﺍﺪﺣ ﻪﮐ ﯼﺍ n ﺩﺭﺍﺩ ﺖﻘﺑﺎﻄﻣ ﺩﺭﺍﺩ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻩﺪﻨﻨﮐﺮﯿﯿﻐﺗ: ﺕﺎﺤﯿﺿﻮﺗ: ﺮﺘﺸﯿﺑ ﺎﯾ ﺮﻔﺻ ﯼﻭﺎﺣ ﻪﮐ ﯼﺍ ﻪﺘﺷﺭ ﺮﻫ ﺎﺑ n ﺩﺭﺍﺩ ﺖﻘﺑﺎﻄﻣ ﺪ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻩﺪﻨﻨﮐﺮﯿﯿﻐﺗ: ﺕﺎﺤﯿﺿﻮﺗ: ﺯﺍ ﺩﺭﻮﻣ ﮏﯾ ﺎﯾ ﺮﻔﺻ ﯼﻭﺎﺣ ﻪﮐ ﯼﺍ ﻪﺘﺷﺭ ﺮﻫ ﺎﺑ n ﺩﺭﺍﺩ ﺖﻘﺑ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺖﺳﺍ ﻥﺁ ﺎﺑ ﻢﻈﻨﻣ ﺕﺭﺎﺒﻋ ءﯽﺷ ﮏﯾ RegExp ﯽﺷ ،ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ .ﺖﺳﺍ RegExp ﻥﺎﯿﺑ ﺵﻭﺭ ﮏﯾ ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ true ﻭ ﺪﻨﮐ ﯽﻣ ﻮﺠﺘﺴﺟ ﻮﮕﻟﺍ ﮏﯾ ﯼﺍﺮﺑ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ :ﺪﻨﮐ ﯽﻣ ﻮﺠﺘﺴﺟ "e" ﺮﺘﮐﺍﺭﺎﮐ ﯼﺍﺮﺑ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ ﺮﯾﺯ ﻝﺎﺜﻣ :ﺩﻮﺑ ﺪﻫﺍﻮﺧ ﺮﯾﺯ ﺕﺭﻮﺻ ﻪﺑ ﻻﺎﺑ ﺪﮐ ﯽﺟﻭﺮﺧ ،ﺩﺭﺍﺩ ﺩﻮﺟﻭ ﻪﺘﺷﺭ ﺭﺩ "e" ﮏﯾ ﻪﮐ ﯽﯾﺎﺠﻧﺁ ﺯﺍ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ ﻭﺩ ﻦﯾﺍ .ﺪﯿﻫﺩ ﺭﺍﺮﻗ ﺮﯿﻐﺘﻣ ﮏﯾ ﺭﺩ ﺍﺭ ﻢﻈﻨﻣ ﺕﺭﺎﺒﻋ ﺍﺪﺘﺑﺍ ﺖﺴﯿﻧ ﻡﺯﻻ .ﺖﺳﺍ RegExp ﻥﺎﯿﺑ ﺵﻭﺭ ﮏﯾ ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﻥﺍﻮﻨﻋ ﻪﺑ ﺍﺭ ﻩﺪﺷ ﺖﻓﺎﯾ ﻦﺘﻣ ﻭ ﺪﻨﮐ ﯽﻣ ﻮﺠﺘﺴﺟ ﺺﺨﺸﻣ ﯼﻮﮕﻟﺍ ﮏﯾ ﯼﺍﺮﺑ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ .ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ (null) ﯽﻟﺎﺧ ﯽﺷ ﮏﯾ ،ﺪﺸﻧ ﺍﺪﯿﭘ ﺖﻘﺑﺎﻄﻣ ﺮﮔﺍ :ﺪﻨﮐ ﯽﻣ ﻮﺠﺘﺴﺟ "e" ﺮﺘﮐﺍﺭﺎﮐ ﯼﺍﺮﺑ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ ﺮﯾﺯ ﻝﺎﺜﻣ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ ﺪﯾﻭﺮﺑ ﺎﻣ Complete ﻪﺑ ،ﻞﻣﺎﮐ ﻊﺟﺮﻣ ﮏﯾ ﯼﺍﺮﺑ ﺖﺳﺍ RegExp ﻡﺎﻤﺗ ﺯﺍ ﯽﯾﺎﻫ ﻪﻧﻮﻤﻧ ﻭ ﺕﺎﺤﯿﺿﻮﺗ ﯼﻭﺎﺣ ﻊﺟﺮﻣ ﻝﺎﺜﻣ
let text = "Visit W3Schools!";
let n = text.search("W3Schools");
6
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript String Methods</h1>
<p>Search a string for "W3Schools", and display the position of the match:</p>
<p id="demo"></p>
<script>
let text = "Visit W3Schools!";
let n = text.search("W3Schools");
document.getElementById("demo").innerHTML = n;
</script>
</body>
</html>
ﻢﻈﻨﻣ ﺕﺭﺎﺒﻋ ﮏﯾ ﺎﺑ
search()
ﻪﺘﺷﺭ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﻝﺎﺜﻣ
let text = "Visit W3Schools";
let n = text.search(/w3schools/i);
6
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Regular Expressions</h2>
<p>Search a string for "w3Schools", and display the position of the match:</p>
<p id="demo"></p>
<script>
let text = "Visit W3Schools!";
let n = text.search(/w3Schools/i);
document.getElementById("demo").innerHTML = n;
</script>
</body>
</html>
ﻪﺘﺷﺭ ﮏﯾ ﺎﺑ
replace()
ﻪﺘﺷﺭ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍlet text = "Visit Microsoft!";
let result = text.replace("Microsoft", "W3Schools");
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript String Methods</h1>
<p>Replace "Microsoft" with "W3Schools" in the paragraph below:</p>
<button onclick="myFunction()">Try it</button>
<p id="demo">Please visit Microsoft!</p>
<script>
function myFunction() {
let text = document.getElementById("demo").innerHTML;
document.getElementById("demo").innerHTML =
text.replace("Microsoft","W3Schools");
}
</script>
</body>
</html>
ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻢﻈﻨﻣ ﺕﺭﺎﺒﻋ ﮏﯾ ﺎﺑ
ﻝﺎﺜﻣ
let text = "Visit Microsoft!";
let result = text.replace(/microsoft/i, "W3Schools");
Visit W3Schools!
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript String Methods</h2>
<p>Replace "Microsoft" with "W3Schools" in the paragraph below:</p>
<button onclick="myFunction()">Try it</button>
<p id="demo">Please visit Microsoft!</p>
<script>
function myFunction() {
let text = document.getElementById("demo").innerHTML;
document.getElementById("demo").innerHTML =
text.replace(/microsoft/i, "W3Schools");
}
</script>
</body>
</html>
؟ﺪﯾﺩﺮﮐ ﻪﺟﻮﺗ ﺎﯾﺁ
.ﺪﻧﻮﺷ ﻩﺩﺎﻔﺘﺳﺍ ﻻﺎﺑ ﯼﺎﻫ ﺵﻭﺭ ﺭﺩ ﺪﻨﻧﺍﻮﺗ ﯽﻣ (ﯼﺍ ﻪﺘﺷﺭ ﯼﺎﻫ ﻥﺎﻣﻮﮔﺭﺁ ﯼﺎﺟ ﻪﺑ) ﻢﻈﻨﻣ ﺕﺭﺎﺒﻋ ﯼﺎ ﻢﻈﻨﻣ ﻥﺎﯿﺑ ﯼﺎﻫ ﻩﺪﻨﻨﮐ ﺡﻼﺻﺍ
i
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Regular Expressions</h2>
<p>Do a case-insensitive search for "w3schools" in a string:</p>
<p id="demo"></p>
<script>
let text = "Visit W3Schools";
let result = text.match(/w3schools/i);
document.getElementById("demo").innerHTML = result;
</script>
</body>
</html>
g
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Regular Expressions</h2>
<p>Do a global search for "is" in a string:</p>
<p id="demo"></p>
<script>
let text = "Is this all there is?";
let result = text.match(/is/g);
document.getElementById("demo").innerHTML = result;
</script>
</body>
</html>
m
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Regular Expressions</h2>
<p>Do a multiline search for "is" at the beginning of each line in a string:</p>
<p id="demo"></p>
<script>
let text = "\nIs th\nis it?";
let result = text.match(/^is/m);
document.getElementById("demo").innerHTML = "Result is: " + result;
</script>
</body>
</html>
ﻢﻈﻨﻣ ﻥﺎﯿﺑ ﯼﺎﻫﻮﮕﻟﺍ
[abc]
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Regular Expressions</h2>
<p>Do a global search for the character "h" in a string:</p>
<p id="demo"></p>
<script>
let text = "Is this all there is?";
let result = text.match(/[h]/g);
document.getElementById("demo").innerHTML = result;
</script>
</body>
</html>
[0-9]
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Regular Expressions</h2>
<p>Do a global search for the numbers 1 to 4 in a string:</p>
<p id="demo"></p>
<script>
let text = "123456789";
let result = text.match(/[1-4]/g);
document.getElementById("demo").innerHTML = result;
</script>
</body>
</html>
(x|y)
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Regular Expressions</h2>
<p>Do a global search for any of the specified alternatives (red|green):</p>
<p id="demo"></p>
<script>
let text = "re, green, red, green, gren, gr, blue, yellow";
let result = text.match(/(red|green)/g);
document.getElementById("demo").innerHTML = result;
</script>
</body>
</html>
\d
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Regular Expressions</h2>
<p>Do a global search for digits in a string:</p>
<p id="demo"></p>
<script>
let text = "Give 100%!";
let result = text.match(/\d/g);
document.getElementById("demo").innerHTML = result;
</script>
</body>
</html>
\s
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Regular Expressions</h2>
<p>Do a global search for whitespace characters in a string:</p>
<p id="demo"></p>
<script>
let text = "Is this all there is?";
let result = text.match(/\s/g);
document.getElementById("demo").innerHTML = result;
</script>
</body>
</html>
\b
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Regular Expressions</h2>
<p>Search for the characters "LO" in the <b>beginning</b> of a word in the phrase:</p>
<p>"HELLO, LOOK AT YOU!"</p>
<p>Found in position: <span id="demo"></span></p>
<script>
let text = "HELLO, LOOK AT YOU!";
let result = text.search(/\bLO/);
document.getElementById("demo").innerHTML = result;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Regular Expressions</h2>
<p>Search for the characters "LO" in the <b>end</b> of a word in the phrase:</p>
<p>"HELLO, LOOK AT YOU!"</p>
<p>Found in position: <span id="demo"></span></p>
<script>
let text = "HELLO, LOOK AT YOU!";
let result = text.search(/LO\b/);
document.getElementById("demo").innerHTML = result;
</script>
</body>
</html>
\uxxxx
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Regular Expressions</h2>
<p>Do a global search for the hexadecimal number 0057 (W) in a string:</p>
<p id="demo"></p>
<script>
let text = "Visit W3Schools. Hello World!";
let result = text.match(/\u0057/g);
document.getElementById("demo").innerHTML = result;
</script>
</body>
</html>
n+
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Regular Expressions</h2>
<p>Do a global search for at least one "o" in a string:</p>
<p id="demo"></p>
<script>
let text = "Hellooo World! Hello W3Schools!";
let result = text.match(/o+/g);
document.getElementById("demo").innerHTML = result;
</script>
</body>
</html>
n*
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Regular Expressions</h2>
<p>Do a global search for an "l", followed by zero or more "o" characters:</p>
<p id="demo"></p>
<script>
let text = "Hellooo World! Hello W3Schools!";
let result = text.match(/lo*/g);
document.getElementById("demo").innerHTML = result;
</script>
</body>
</html>
n?
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Regular Expressions</h2>
<p>Do a global search for a "1", followed by zero or one "0" characters:</p>
<p id="demo"></p>
<script>
let text = "1, 100 or 1000?";
let result = text.match(/10?/g);
document.getElementById("demo").innerHTML = result;
</script>
</body>
</html>
RegExp ﯽﺷ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ
()test ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ
test()
ﺵﻭﺭ ﻝﺎﺜﻣ
const pattern = /e/;
pattern.test("The best things in life are free!");
true
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Regular Expressions</h2>
<p>Search for an "e" in the next paragraph:</p>
<p id="p01">The best things in life are free!</p>
<p id="demo"></p>
<script>
let text = document.getElementById("p01").innerHTML;
const pattern = /e/;
document.getElementById("demo").innerHTML = pattern.test(text);
</script>
</body>
</html>
/e/.test("The best things in life are free!");
()exec ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ
exec()
ﺵﻭﺭ ﻝﺎﺜﻣ
/e/.exec("The best things in life are free!");
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Regular Expressions</h2>
<p id="demo"></p>
<script>
const obj = /e/.exec("The best things in life are free!");
document.getElementById("demo").innerHTML =
"Found " + obj[0] + " in position " + obj.index + " in the text: " + obj.input;
</script>
</body>
</html>
ﺪﯿﻨﮐ ﻞﻣﺎﮐ ﺍﺭ RegExp ﻊﺟﺮﻣ