# More regex woes

**URL:** <https://forum.servoy.com/t/more-regex-woes/16127>\
**Category:** Classic Servoy\
**Created:** [July 2, 2012, 9:03pm UTC](https://forum.servoy.com/t/more-regex-woes/16127 "2012-07-02T21:03:29Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![djlapin](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@djlapin](https://forum.servoy.com/u/djlapin)\
**Post date:** [July 2, 2012, 9:03pm UTC](https://forum.servoy.com/t/more-regex-woes/16127/1 "2012-07-02T21:03:29Z")

</div>

Suppose (this is a simplification) –

```auto
var aCompany = ['Smith-Kline', 'Smith-Burton', 'Williams-French'];
var testExp = new RegExp("/^" + companyName + "\-/i"); 
for(var i = 0; i < aCompany.length; i++) {
     if((aCompany[i]) && (aCompany.match(testExp))) {
           ...do something
     }
}

```

Although “Smith-Kline” should match on /^Smith-/i, it doesn’t in the code. Using the interactive console, however, I can get a true value on aCompany\*.match(/^Smith-/i).\*  
_I also tried defining testExp = “/^” + companyName + “-/i”; however, that didn’t work, either._  
_What will get this to work?_  
_Thank you,_  
_Don_

---

<div class="post-metadata">

**Author:** ![Joas](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/joas/32/5095_2.png) [@Joas](https://forum.servoy.com/u/Joas)\
**Post date:** [July 3, 2012, 10:30am UTC](https://forum.servoy.com/t/more-regex-woes/16127/2 "2012-07-03T10:30:10Z")

</div>

When you use new RegExp, you shouldn’t include the surrounding slashes. Try this instead:

```auto
	var testExp = new RegExp("^" + companyName + "\-");
	testExp.ignoreCase = true;

```

Also, you forgot to add _in the item you are matching. So the entire code should be:_  
_```_

- var aCompany = [‘Smith-Kline’, ‘Smith-Burton’, ‘Williams-French’];  
var testExp = new RegExp(“^” + companyName + “-”);  
testExp.ignoreCase = true;  
for(var i = 0; i \< aCompany.length; i++) {  
if((aCompany[i]) && (aCompany[i].match(testExp))) {  
…do something  
}  
}\*  
_```_

---

<div class="post-metadata">

**Author:** ![djlapin](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@djlapin](https://forum.servoy.com/u/djlapin)\
**Post date:** [July 3, 2012, 8:34pm UTC](https://forum.servoy.com/t/more-regex-woes/16127/3 "2012-07-03T20:34:38Z")

</div>

Thank you Joas!

Don

---

<div class="post-metadata">

**Author:** ![djlapin](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@djlapin](https://forum.servoy.com/u/djlapin)\
**Post date:** [July 6, 2012, 8:11pm UTC](https://forum.servoy.com/t/more-regex-woes/16127/4 "2012-07-06T20:11:20Z")

</div>

A follow up on this –

When I try passing a uid to a method,

```auto
var recordExp = new RegExp(record_uid.toString());
recordExp.ignoreCase = true;

```

If i test it in the interactive console, Servoy appears to not honor the ignoreCase request. A match() later in the code fails even though the only difference is case. However, it will work if I try instead to match on record\_uid.toString().toLowerCase().

Anybody know about this?

Thank you,  
Don

---

<div class="post-metadata">

**Author:** ![Joas](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/joas/32/5095_2.png) [@Joas](https://forum.servoy.com/u/Joas)\
**Post date:** [July 9, 2012, 7:28am UTC](https://forum.servoy.com/t/more-regex-woes/16127/5 "2012-07-09T07:28:21Z")

</div>

Does your uuid contain dashes “-” ? Because in that case the regexp may be something else than you think. You should escape all dashes with a slash: -

---

<div class="post-metadata">

**Author:** ![djlapin](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@djlapin](https://forum.servoy.com/u/djlapin)\
**Post date:** [July 10, 2012, 5:57am UTC](https://forum.servoy.com/t/more-regex-woes/16127/6 "2012-07-10T05:57:37Z")

</div>

Hi Joas,

The UIDs are Servoy-assigned, and contain the dashes.

But when the UserManager plugin returns the record UIDs as a dataset of locked records, the UIDs are lowercase. I am trying to match up the returned UIDs with a particular record’s UID (to see who has locked the record).

So to make .match() work, I would need to replace each instance of a “-” with a “-” ?

Thank you,  
Don

---

<div class="post-metadata">

**Author:** ![Joas](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/joas/32/5095_2.png) [@Joas](https://forum.servoy.com/u/Joas)\
**Post date:** [July 11, 2012, 11:21am UTC](https://forum.servoy.com/t/more-regex-woes/16127/7 "2012-07-11T11:21:07Z")

</div>

> djlapin:  
> I would need to replace each instance of a “-” with a “-” ?

Yes, because if you have an uuid containing for example 1-4, then it doesn’t match the string “1-4”, but only the strings “1”, “2”, “3” and “4”. So that will give you strange results.

---

<div class="post-metadata">

**Author:** ![djlapin](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@djlapin](https://forum.servoy.com/u/djlapin)\
**Post date:** [July 11, 2012, 11:51pm UTC](https://forum.servoy.com/t/more-regex-woes/16127/8 "2012-07-11T23:51:11Z")

</div>

Thank you for explaining - very confusing for me.

Don

---

<div class="post-metadata">

**Author:** ![Joas](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/joas/32/5095_2.png) [@Joas](https://forum.servoy.com/u/Joas)\
**Post date:** [July 18, 2012, 7:17am UTC](https://forum.servoy.com/t/more-regex-woes/16127/9 "2012-07-18T07:17:53Z")

</div>

I think it will help you all lot to read a tutorial on regular expressions in javascript, for example [this one](http://www.javascriptkit.com/javatutors/re.shtml).

---

<div class="post-metadata">

**Author:** ![omar](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@omar](https://forum.servoy.com/u/omar)\
**Post date:** [July 18, 2012, 8:20am UTC](https://forum.servoy.com/t/more-regex-woes/16127/10 "2012-07-18T08:20:13Z")

</div>

I also like this regex chapter on the Mozilla Developer Network: [Regular expressions - JavaScript | MDN](https://developer.mozilla.org/en/JavaScript/Guide/Regular_Expressions)

as well as this one: [Intro to JavaScript | WebReference](http://www.webreference.com/js/column5/index.html)

and this online regulare expression tester can be handy too: [JavaScript RegExp Example: Online Regular Expression Tester](http://www.regular-expressions.info/javascriptexample.html)

---

<div class="post-metadata">

**Author:** ![djlapin](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@djlapin](https://forum.servoy.com/u/djlapin)\
**Post date:** [July 20, 2012, 7:45pm UTC](https://forum.servoy.com/t/more-regex-woes/16127/11 "2012-07-20T19:45:43Z")

</div>

Thanks, guys. It’s really like another language ![:o]( "Surprised")

---

<div class="post-metadata">

**Author:** ![mattfrizzell](https://avatars.discourse-cdn.com/v4/letter/m/d78d45/32.png) [@mattfrizzell](https://forum.servoy.com/u/mattfrizzell)\
**Post date:** [July 24, 2012, 6:25pm UTC](https://forum.servoy.com/t/more-regex-woes/16127/12 "2012-07-24T18:25:57Z")

</div>

My favorite comment on this subject is, _“Some people, when confronted with a problem, think “I know, I’ll use regular expressions.” Now they have two problems.”_

---

<div class="post-metadata">

**Author:** ![Joas](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/joas/32/5095_2.png) [@Joas](https://forum.servoy.com/u/Joas)\
**Post date:** [July 25, 2012, 8:24am UTC](https://forum.servoy.com/t/more-regex-woes/16127/13 "2012-07-25T08:24:21Z")

</div>

Depending on the people I would say they have: (problem){0,2} ![;)]( "Wink")
