-5

I am looking for regular expression for exact letters in middle of word. which should match Dot(.) also.

Currently I am using regular expression is "\\w*."+inputString +"\\w*", "i" , actually period represents any letter in this expression.

eg:
inputData = {name:[abc.12, abcdef, bc1454, test, rahul, bc.reju, rewbc.]} inputString = "bc." var wordFormat = new RegExp('\\w*'+inputString +'\\w*', 'i'); workFormat.test(inputData);

scenario 1: Starting of word.
input : 'bc.'
actual output is: abc.12 expecting output is: abc.12, bc.reju, rewbc.

expect output should get only one because passing inputString matches only one item in array of object (inputData) so, expecting output item is 1.

Wiktor Stribiżew
  • 484,719
  • 26
  • 302
  • 397
lucky
  • 19
  • 9
  • 2
    Please don't tag-spam. This has nothing to do with jQuery, and it will *either* have to do with JavaScript, C#, **or** nsregularexpression, not all three. Please fix the tags. Also: *"actual output is"* Actual output **of what**? You've shown no code. – T.J. Crowder Jul 21 '17 at 13:47
  • `.` is a special character in regex - so you need to escape it - should be `\\.` in your case or `[.]` – Sebastian Proske Jul 21 '17 at 13:47

2 Answers2

0

Here is a demo - Regex101

You can modify this by replacing the "bc" with your search string.

\w*bc\w*\.\d*

updated Expression

\w*bc\.\d*
lucky
  • 19
  • 9
  • Thank you so much for given great expression. but above expression returns only middle of words. 1.it's accept middle of words. 2.not detects and at start and end of words. 3.sometimes user are not enter DOT(.) also. Please share me expression which should satisfy above all three conditions. – lucky Jul 21 '17 at 15:27
  • Can you provide better examples of input and expected output? –  Jul 21 '17 at 16:18
  • updated Expression `\w*bc\.\d*` – Moshe Slavin Feb 17 '19 at 10:06
0

Here is the example that you can use as your requirement:

   regular = "bc." //These was the actual input expression you want to test

    var regularplacholder = '[character]'; 
    var regularexpresion="/";
    for(var index =0;index<regular.length;index++)
   {
    regularexpresion+=(regularplacholder.replace('character',regular[index]));
   }
   regularexpresion+='*'

   if(regularexpresion.test('test string')){
     //your logic here
   }