Question

Write a javascript function to match string starting with .AB or AB The string should either...

Write a javascript function to match string starting with .AB or AB

The string should either start with .AB or AB followed by any characters.

i am getting confused how to form regular expression and tech and match using function . the string should match with the first two characters AB or first three characters .AB then only alert statement("string is correct") otherwise alert statement ("String is not correct")

input1 : .AB2e234324

output: string is correct

input2 : AB44r4r44r

output: string is correct

input3 : ABdsfdsfds

output: string is correct

input4 : AfB.dsf3

output string is incorrect

=======================

The language is Javascript.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

OUTPUT

CODE TO COPY

<!DOCTYPE html>
<html>
<body>

<script>
function fun(a) {
if(a[0] == '.' && a[1] == 'A' && a[2] == 'B')
   alert("string is correct");
else if(a[0] == 'A' && a[1] == 'B')
   alert("string is correct");
else
    alert("string is incorrect");
}
fun(".AB2e234324");
</script>

</body>
</html>

// Please up vote. Happy Learning!

Add a comment
Know the answer?
Add Answer to:
Write a javascript function to match string starting with .AB or AB The string should either...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVASCRIPT FUNCTIONS Write the isPrime function and the applySipping Cost function. Then, complete the code as...

    JAVASCRIPT FUNCTIONS Write the isPrime function and the applySipping Cost function. Then, complete the code as indicated at the end in comments var cart=1 {"name":"Biscuits", "type":"regular", "category":"food", "price": 2.0}, {"name":"Monitor", "type":"prime", "category":"tech", "price": 120}, {"name":"Mouse", "type":"prime", "category":"tech", "price": 25}, {"name":"dress", "type":"regular", "category":"clothes", "price": 50}, {"name":"XL Monitor","type":"prime", "category":"tech", "price": 160}, {"name":"Cookies","type":"regular", "category":"food", "price:16). function isPrime(item) { //WRITE THIS FUNCTION // should return true if the item's type is "prime" and false otherwise let iskotPrime = item => 'isPrime(item); let applyCoupon =...

  • please implement this function by C language Write a string compare function which returns 1 if the strings match for n characters starting at offset m, O if the strings don't match. You must chec...

    please implement this function by C language Write a string compare function which returns 1 if the strings match for n characters starting at offset m, O if the strings don't match. You must check if m is within the length of both s and t. int submatch(char* s, char* t, int n, int m) Write a string compare function which returns 1 if the strings match for n characters starting at offset m, O if the strings don't match....

  • using c language String Challenge Have the function StringChallenge(str) read str which will contain two strings...

    using c language String Challenge Have the function StringChallenge(str) read str which will contain two strings separated by a space. The first string will consist of the following sets of characters: +, *, $, and {N} which is optional. The plus (+) character represents a single alphabetic character, the ($) character represents a number between 1-9, and the asterisk (*) represents a sequence of the same character of length 3 unless it is followed by {N} which represents how many...

  • using java String Challenge Have the function StringChallenge(str) read str which will contain two strings...

    Have the function wildcard(str) read str which will contain two strings separated by a space.The first string will consist of the following sets of characters: +, *, $ and {N} which is optional.The plus (+) character represents a single alphabetic character, the ($) character represents anumber between 1-9, and asterisk (*) represents a sequence of the same character of length 3unless it is followed by {N} which represents how many characters would appear in thesequence where N will be at...

  • Write a program that replace repeated three characters in a string by the character followed by 3...

    Write a program that replace repeated three characters in a string by the character followed by 3. For example, the string aabccccaaabbbbcc would become aabc3ca3b3cc. When there are more than three repeated characters, the first three characters will be replaced by the character followed by 3. You can assume the string has only lowercase letters (a-z). Your program should include the following function: void replace(char *str, char *replaced); Your program should include the following function: void replace(char *str, char *replaced);...

  • Stuck on this computer science assignment Write a program that demonstrates binary searching through an array...

    Stuck on this computer science assignment Write a program that demonstrates binary searching through an array of strings and finding specific values in an corresponding parallel double array. In all cases your output should exactly match the provided solution.o. Provided files: Assignment.cpp - starter assignment with function prototypes companies.txt - file for program to read. earnings.txt - file for program to read. Input1.txt Input2.txt - Test these inputs out manually, or use stream redirection Input3.txt - These inputs are based...

  • Write a program that uses a recursive function to determine whether a string is a character-unit...

    Write a program that uses a recursive function to determine whether a string is a character-unit palindrome. Moreover, the options for doing case sensitive comparisons and not ignoring spaces are indicated with flags. For example "A nut for a jar of tuna" is a palindrome if spaces are ignored and not otherwise. "Step on no pets" is a palindrome whether spaces are ignored or not, but is not a palindrome if it is case sensitive. Background Palindromes are character sequences...

  • 1.1. Write a function named "areFirstTwoTheSame AsLast TwoChars" that accepts a string. It returns true if...

    1.1. Write a function named "areFirstTwoTheSame AsLast TwoChars" that accepts a string. It returns true if the first two characters and the last two characters of the string are the same. It returns false otherwise. In addition, if the string is empty or has only one character, it also returns false. For example, these are the strings with their expected return values false falsc "AB" true "ABA" false "ABAB" trus "ABBA" false "ABCABC false "ABCCAB" true 1.2 Write a function...

  • This is a multipart question, needs to be in c language, and be able to compile...

    This is a multipart question, needs to be in c language, and be able to compile into a windows program, i.e. code blocks, specifically. In C language: You are to design a fight game between Neo versus Smith. The program needs to be organized using at least three functions. The specifications are as follows: The program should first call a password function. Request a password, multiple characters followed by return. For every character entered, display * character. The correct password...

  • Please I need help with this c++ code. please show all steps , write comments and...

    Please I need help with this c++ code. please show all steps , write comments and show sample runs. Thank you. 1. The Federal Bureau of Investigation (FBI) has recently changed its Universal Control Numbers (UCN) for identifying individuals who are in the FBI's fingerprint database to an eight-digit base 27 value with a ninth check digit. The digits used are: 0123456789ACDE FHJKLMNPRTVWX Some letters are not used because of possible confusion with other digits: B->8, G->C, I- >1, 0->0,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT