RegExp ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ


فهرست مطالب

    نمایش فهرست مطالب


ﺪﻫﺩ ﯽﻣ ﻞﯿﮑﺸﺗ ﺍﺭ a ﻪﮐ ﺖﺳﺍ ﺎﻫﺮﺘﮐﺍﺭﺎﮐ ﺯﺍ ﯼﺍ ﻪﻟﺎﺒﻧﺩ ﻢﻈﻨﻣ ﺕﺭﺎﺒﻋ ﮏﯾ

ﺩﺮﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻦﺘﻣ ﯽﻨﯾﺰﮕﯾﺎﺟ ﻭ ﻦﺘﻣ ﯼﻮﺠﺘﺴﺟ ﯼﺍﺮﺑ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ ﻮﺠﺘﺴﺟ ﯼﻮﮕﻟﺍ


؟ﺖﺴﯿﭼ ﻢﻈﻨﻣ ﺕﺭﺎﺒﻋ ﮏﯾ

ﺪﻫﺩ ﯽﻣ ﻞﯿﮑﺸﺗ ﺍﺭ ﻮﺠﺘﺴﺟﮏﯾ ﻪﮐ ﺖﺳﺍ ﺎﻫﺮﺘﮐﺍﺭﺎﮐ ﺯﺍ ﯼﺍ ﻪﻟﺎﺒﻧﺩ ،ﻢﻈﻨﻣ ﺕﺭﺎﺒﻋ ﮏﯾ

.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺪﯿﻨﮐﯽﻣ ﻮﺠﺘﺴﺟ ﻪﭽﻧﺁ ﻒﯿﺻﻮﺗ ﯼﺍﺮﺑ ﻮﺠﺘﺴﺟ ﯼﻮﮕﻟﺍ ﻦﯾﺍ ﺯﺍ ﺪﯿﻧﺍﻮﺗﯽﻣ ،ﺪﯿﻨ

.ﺪﺷﺎﺑ ﺮﺗ ﻩﺪﯿﭽﯿﭘ ﯼﻮﮕﻟﺍ ﮏﯾ ﺎﯾ ﺪﺣﺍﻭ ﺮﺘﮐﺍﺭﺎﮐ ﮏﯾ ﺪﻧﺍﻮﺗ ﯽﻣ ﻢﻈﻨﻣ ﺕﺭﺎﺒﻋ ﮏﯾ

ﺩﺮﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻢﻈﻨﻣ ﺕﺍﺭﺎﺒﻋ ﺯﺍ ﻥﺍﻮﺗ ﯽﻣ ﻦﺘﻣ ﯼﻮﺠﺘﺴﺟ ﻉﺍﻮﻧﺍ ﻪﻤﻫ ﻡﺎﺠﻧﺍ ﯼﺍﺮﺑ

ﻮﺤﻧ

/pattern/modifiers;

ﻝﺎﺜﻣ

/w3schools/i;

:ﻩﺪﺷ ﻩﺩﺍﺩ ﺢﯿﺿﻮﺗ ﻝﺎﺜﻣ

/w3schools/i ﺖﺳﺍ ﻢﻈﻨﻣ ﺕﺭﺎﺒﻋ ﮏﯾ.

w3schools (ﻮﺠﺘﺴﺟ ﺭﺩ ﻩﺩﺎﻔﺘﺳﺍ ﯼﺍﺮﺑ) ﺖﺳﺍ ﻮﮕﻟﺍ ﮏﯾ.

i ﺡﻼﺻﺍ ﮏﯾﺖﺳﺍ ﻩﺪﻨﻨﮐ (ﯽﻣ ﺮﯿﯿﻐﺗ ﯽﮔﺭﺰﺑ ﻪﺑ ﺍﺭ ﻮﺠﺘﺴﺟﺪﻫﺩ).


ﯼﺍ ﻪﺘﺷﺭ ﯼﺎﻫ ﺵﻭﺭ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ

ﺩﻮﺷ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﻪﺘﺷﺭ ﻭﺩ ﺎﺑ ﺐﻠﻏﺍ ﻢﻈﻨﻣ ﺕﺍﺭﺎﺒﻋ ،ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ

ﮏﯾ ﯼﻮﺠﺘﺴﺟ ﯼﺍﺮﺑ ﺕﺭﺎﺒﻋ ﮏﯾ ﺯﺍ search() ﺵﻭﺭ

ﻥﺁ ﺭﺩ ﻪﮐ ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﻪﺘﻓﺎﯾ ﺮﯿﯿﻐﺗ ﻪﺘﺷﺭ ﮏﯾ replace()


ﻪﺘﺷﺭ ﮏﯾ ﺎﺑ search()

:ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﻖﺑﺎﻄﺗ ﺖﯿﻌﻗﻮﻣ ﻭ ﺪﻨﮐ ﯽﻣ ﻮﺠﺘﺴﺟ ﺺﺨﺸﻣ ﺭﺍﺪﻘﻣ ﮏﯾ ﯼﺍﺮﺑ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ

ﻝﺎﺜﻣ

:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻪﺘﺷﺭ ﮏﯾ ﺭﺩ "W3schools" ﯼﻮﺠﺘﺴﺟ ﯼﺍﺮﺑ ﻪﺘﺷﺭ ﮏﯾ ﺯﺍ

let text = "Visit W3Schools!";
let n = text.search("W3Schools");

:ﺩﻮﺑ ﺪﻫﺍﻮﺧ n ﺭﺩ ﻪﺠﯿﺘﻧ

6

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript String Methods</h1>
<p>Search a string for &quot;W3Schools&quot;, 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() ﻪﺘﺷﺭ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ

ﻝﺎﺜﻣ

:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻪﺘﺷﺭ ﮏﯾ ﺭﺩ "w3schools" ﯼﺍﺮﺑ ﮒﺭﺰﺑ ﻑﻭﺮﺣ ﻥﻭﺪﺑ ﯼﻮﺠﺘﺴﺟ ﻡﺎﺠﻧﺍ ﯼﺍﺮﺑ ﯽﻟﻮﻤﻌﻣ ﺕﺭﺎ

let text = "Visit W3Schools";
let n = text.search(/w3schools/i);

:ﺩﻮﺑ ﺪﻫﺍﻮﺧ n ﺭﺩ ﻪﺠﯿﺘﻧ

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 &quot;Microsoft&quot; with &quot;W3Schools&quot; 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>



ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻢﻈﻨﻣ ﺕﺭﺎﺒﻋ ﮏﯾ ﺎﺑ replace()

ﻝﺎﺜﻣ

ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﮏﭼﻮﮐ ﻭ ﮒﺭﺰﺑ ﻑﻭﺮﺣ ﻪﺑ ﺱﺎﺴﺣ ﺮﯿﻏ ﻢﻈﻨﻣ ﺕﺭﺎﺒﻋ ﮏﯾ ﺯﺍ W3Schools ﺎﺑ ﺖﻓﺎﺳﻭﺮﮑﯾﺎﻣ ﯽﻨ

let text = "Visit Microsoft!";
let result = text.replace(/microsoft/i, "W3Schools");

:ﺩﻮﺑ ﺪﻫﺍﻮﺧ res ﺭﺩ ﻪﺠﯿﺘﻧ

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

ﺕﺎﺤﯿﺿﻮﺗ: ﺪﯿﻨﮐ ﺍﺪﯿﭘ ﺖﻘﺑﺎﻄﻣ ﺩﺭﻮﻣ ﻦﯾﺍ ﺪﻨﻧﺎﻣ ﯼﺍ ﻪﻤﻠﮐ ﯼﺍﺪﺘﺑﺍ ﺭﺩ: \bWORD ﻪ

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!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

ﺕﺎﺤﯿﺿﻮﺗ: ﻪﺴﯾﻮﻧ Unicode ﻝﺎﻤﯿﺳﺩ ﺍﺰﮕﻫ ﺩﺪﻋ ﻂﺳﻮﺗ ﻩﺪﺷ ﺺﺨﺸﻣ xxxx ﺪﯿﻨﮐ ﺍﺪﯿﭘ

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ

<!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+

ﺕﺎﺤﯿﺿﻮﺗ: ﻪﺘﺷﺭ ﺮﻫ ﺎﺑﮏﯾ ﻞﻗﺍﺪﺣ ﻪﮐ ﯼﺍ 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*

ﺕﺎﺤﯿﺿﻮﺗ: ﺮﺘﺸﯿﺑ ﺎﯾ ﺮﻔﺻ ﯼﻭﺎﺣ ﻪﮐ ﯼﺍ ﻪﺘﺷﺭ ﺮﻫ ﺎﺑ 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?

ﺕﺎﺤﯿﺿﻮﺗ: ﺯﺍ ﺩﺭﻮﻣ ﮏﯾ ﺎﯾ ﺮﻔﺻ ﯼﻭﺎﺣ ﻪﮐ ﯼﺍ ﻪﺘﺷﺭ ﺮﻫ ﺎﺑ 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 ﯽﺷ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ

ﺖﺳﺍ ﻥﺁ ﺎﺑ ﻢﻈﻨﻣ ﺕﺭﺎﺒﻋ ءﯽﺷ ﮏﯾ RegExp ﯽﺷ ،ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ


()test ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ

.ﺖﺳﺍ RegExp ﻥﺎﯿﺑ ﺵﻭﺭ ﮏﯾ test() ﺵﻭﺭ

ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ true ﻭ ﺪﻨﮐ ﯽﻣ ﻮﺠﺘﺴﺟ ﻮﮕﻟﺍ ﮏﯾ ﯼﺍﺮﺑ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ

:ﺪﻨﮐ ﯽﻣ ﻮﺠﺘﺴﺟ "e" ﺮﺘﮐﺍﺭﺎﮐ ﯼﺍﺮﺑ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ ﺮﯾﺯ ﻝﺎﺜﻣ

ﻝﺎﺜﻣ

const pattern = /e/;
pattern.test("The best things in life are free!");

:ﺩﻮﺑ ﺪﻫﺍﻮﺧ ﺮﯾﺯ ﺕﺭﻮﺻ ﻪﺑ ﻻﺎﺑ ﺪﮐ ﯽﺟﻭﺮﺧ ،ﺩﺭﺍﺩ ﺩﻮﺟﻭ ﻪﺘﺷﺭ ﺭﺩ "e" ﮏﯾ ﻪﮐ ﯽﯾﺎﺠﻧﺁ ﺯﺍ

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 ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ

.ﺖﺳﺍ RegExp ﻥﺎﯿﺑ ﺵﻭﺭ ﮏﯾ exec() ﺵﻭﺭ

ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﻥﺍﻮﻨﻋ ﻪﺑ ﺍﺭ ﻩﺪﺷ ﺖﻓﺎﯾ ﻦﺘﻣ ﻭ ﺪﻨﮐ ﯽﻣ ﻮﺠﺘﺴﺟ ﺺﺨﺸﻣ ﯼﻮﮕﻟﺍ ﮏﯾ ﯼﺍﺮﺑ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ

.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ (null) ﯽﻟﺎﺧ ﯽﺷ ﮏﯾ ،ﺪﺸﻧ ﺍﺪﯿﭘ ﺖﻘﺑﺎﻄﻣ ﺮﮔﺍ

:ﺪﻨﮐ ﯽﻣ ﻮﺠﺘﺴﺟ "e" ﺮﺘﮐﺍﺭﺎﮐ ﯼﺍﺮﺑ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ ﺮﯾﺯ ﻝﺎﺜﻣ

ﻝﺎﺜﻣ

/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 ﻊﺟﺮﻣ

ﺪﯾﻭﺮﺑ ﺎﻣ Complete ﻪﺑ ،ﻞﻣﺎﮐ ﻊﺟﺮﻣ ﮏﯾ ﯼﺍﺮﺑ

ﺖﺳﺍ RegExp ﻡﺎﻤﺗ ﺯﺍ ﯽﯾﺎﻫ ﻪﻧﻮﻤﻧ ﻭ ﺕﺎﺤﯿﺿﻮﺗ ﯼﻭﺎﺣ ﻊﺟﺮﻣ

تمامی حقوق محفوظ است. © BasicIT.org • 2023-2024