# In RegexFeaturizer the regex\_string seems not suitable for chinese?

**URL:** <https://forum.rasa.com/t/in-regexfeaturizer-the-regex-string-seems-not-suitable-for-chinese/13281>\
**Category:** Rasa Open Source\
**Created:** [July 22, 2019, 6:16am UTC](https://forum.rasa.com/t/in-regexfeaturizer-the-regex-string-seems-not-suitable-for-chinese/13281 "2019-07-22T06:16:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![journey](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@journey](https://forum.rasa.com/u/journey)\
**Post date:** [July 22, 2019, 6:16am UTC](https://forum.rasa.com/t/in-regexfeaturizer-the-regex-string-seems-not-suitable-for-chinese/13281/1 "2019-07-22T06:16:18Z")

</div>

In the RegexFeaturizer

```python
  # regex matching elements with word boundaries on either side
        regex_string = "(?i)(\\b" + "\\b|\\b".join(elements_sanitized) + "\\b)"
        return regex_string

```

It seems the above code not suitable for chinese.

```python
     # regex matching elements with word boundaries on either side
        regex_string = "(?i)(\\b" + "\\b|\\b".join(elements_sanitized) + "\\b)"
        if self.language == 'zh':
            regex_string = "(?i)(" + "|".join(elements_sanitized) + ")"
        return regex_string

```

whether the above it better?

---

<div class="post-metadata">

**Author:** ![Tanja](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/tanja/32/4696_2.png) [@Tanja](https://forum.rasa.com/u/Tanja)\
**Post date:** [July 22, 2019, 7:39am UTC](https://forum.rasa.com/t/in-regexfeaturizer-the-regex-string-seems-not-suitable-for-chinese/13281/2 "2019-07-22T07:39:09Z")

</div>

@journey Can you maybe share an example which does not work? If it turns out to be a problem, you can also open a [GitHub](https://github.com/RasaHQ/rasa) issue. Thanks.

---

<div class="post-metadata">

**Author:** ![journey](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@journey](https://forum.rasa.com/u/journey)\
**Post date:** [July 22, 2019, 11:48am UTC](https://forum.rasa.com/t/in-regexfeaturizer-the-regex-string-seems-not-suitable-for-chinese/13281/3 "2019-07-22T11:48:32Z")

</div>

@Tanja Thank you for reply me.

Below is the test code,which shows the regex\_string is not suitable for chinese.

```python
import re

elements_sanitized = ["南京", "北京", "上海"]
text = "买一张从南京到上海的火车票"
regex_string1 = "(?i)(\\b" + "\\b|\\b".join(elements_sanitized) + "\\b)"
print(regex_string1)
matches1 = re.finditer(regex_string1, text)
matches1 = list(matches1)
print("matches1 len is:%d" % len(matches1))

regex_string2 = "(?i)(" + "|".join(elements_sanitized) + ")"
print(regex_string2)
matches2 = re.finditer(regex_string2, text)
matches2 = list(matches2)
print("matches2 len is:%d" % len(matches2))

```

---

<div class="post-metadata">

**Author:** ![Tanja](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/tanja/32/4696_2.png) [@Tanja](https://forum.rasa.com/u/Tanja)\
**Post date:** [July 22, 2019, 1:40pm UTC](https://forum.rasa.com/t/in-regexfeaturizer-the-regex-string-seems-not-suitable-for-chinese/13281/4 "2019-07-22T13:40:23Z")

</div>

@journey Thanks for providing the example. Looks like something we should fix in our code. Can you please open a [GitHub issue](https://github.com/RasaHQ/rasa/issues) and link to this forum thread? Thanks. If you want to solve it yourself, just create a PR, we would appreciate it 🙂 Feel free to also tag me in the GitHub issue.

---

<div class="post-metadata">

**Author:** ![journey](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@journey](https://forum.rasa.com/u/journey)\
**Post date:** [July 23, 2019, 12:51am UTC](https://forum.rasa.com/t/in-regexfeaturizer-the-regex-string-seems-not-suitable-for-chinese/13281/5 "2019-07-23T00:51:41Z")

</div>

Hi @Tanja I open a github issue here:

> <https://github.com/RasaHQ/rasa/issues/4069>
>
> \<!-- THIS INFORMATION IS MANDATORY - YOUR ISSUE WILL BE CLOSED IF IT IS MISSING.… If you don't know your Rasa version, use \`rasa --version\`. 
> Please format any code or console output with three ticks \`\`\` above and below.
> If you are asking a usage question (e.g. "How do I do xyz") please post your question on https://forum.rasa.com instead --\>
> 
> \*\*Rasa version\*\*:
> "1.1.2"
> \*\*Rasa X version\*\* (if used & relevant):
> 
> \*\*Python version\*\*:
> 3.7.3
> \*\*Operating system\*\* (windows, osx, ...):
> windows
> \*\*Issue\*\*:
> In RegexFeaturizer the regex\_string seems not suitable for chinese?
> 
> In the RegexFeaturizer
> 
> \`\`\`python
> # regex matching elements with word boundaries on either side
> regex\_string = "(?i)(\\\\b" + "\\\\b|\\\\b".join(elements\_sanitized) + "\\\\b)"
> return regex\_string
> \`\`\`
> 
> It seems the above code not suitable for chinese.
> \`\`\`python
> \# regex matching elements with word boundaries on either side
> regex\_string = "(?i)(\\\\b" + "\\\\b|\\\\b".join(elements\_sanitized) + "\\\\b)"
> if self.language == 'zh':
> regex\_string = "(?i)(" + "|".join(elements\_sanitized) + ")"
> return regex\_string
> \`\`\`
> test code:
> \`\`\`python
> import re
> 
> elements\_sanitized = \["南京", "北京", "上海"\]
> text = "买一张从南京到上海的火车票"
> regex\_string1 = "(?i)(\\\\b" + "\\\\b|\\\\b".join(elements\_sanitized) + "\\\\b)"
> print(regex\_string1)
> matches1 = re.finditer(regex\_string1, text)
> matches1 = list(matches1)
> print("matches1 len is:%d" % len(matches1))
> 
> regex\_string2 = "(?i)(" + "|".join(elements\_sanitized) + ")"
> print(regex\_string2)
> matches2 = re.finditer(regex\_string2, text)
> matches2 = list(matches2)
> print("matches2 len is:%d" % len(matches2))
> \`\`\`
> 
> 
> \*\*Error (including full traceback)\*\*:
> \`\`\`
> 
> \`\`\`
> 
> \*\*Command or request that led to error\*\*:
> \`\`\`
> 
> \`\`\`
> 
> \*\*Content of configuration file (config.yml)\*\* (if relevant):
> \`\`\`yml
> 
> \`\`\`
> 
> \*\*Content of domain file (domain.yml)\*\* (if relevant):
> \`\`\`yml
> 
> \`\`\`

---

<div class="post-metadata">

**Author:** ![sdu-2044](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/sdu-2044/32/3697_2.png) [@sdu-2044](https://forum.rasa.com/u/sdu-2044)\
**Post date:** [September 29, 2019, 9:32am UTC](https://forum.rasa.com/t/in-regexfeaturizer-the-regex-string-seems-not-suitable-for-chinese/13281/6 "2019-09-29T09:32:30Z")

</div>

The english words are seperate by whitespace by default while the chinese words are not.So you just need to remve the “\b“” in the regex
