# PatternReplaceCharFilter and Punctuation Characters

**URL:** <https://discuss.elastic.co/t/patternreplacecharfilter-and-punctuation-characters/75271>\
**Category:** Elasticsearch\
**Created:** [February 16, 2017, 4:30am UTC](https://discuss.elastic.co/t/patternreplacecharfilter-and-punctuation-characters/75271 "2017-02-16T04:30:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![learnes](https://avatars.discourse-cdn.com/v4/letter/l/35a633/32.png) [@learnes](https://discuss.elastic.co/u/learnes)\
**Post date:** [February 16, 2017, 4:30am UTC](https://discuss.elastic.co/t/patternreplacecharfilter-and-punctuation-characters/75271/1 "2017-02-16T04:30:34Z")

</div>

Hi,  
I am currently using the following mapping  
default\_index :  
type : custom  
tokenizer : whitespace  
filter : [word\_delimiter, lowercase]  
filter :  
word\_delimiter :  
type : word\_delimiter  
preserve\_original : true  
split\_on\_numerics : true  
stem\_english\_possessive : false

My current mapping produces the tokens "abc", "def" and "abc!def" for text abc!def.

I would like to search the punctuation characters !"#$%&'()\*+,-./:;\<=\>?@[]^\_`{|}~ also.  
i.e. Expected Tokens are "abc", "!", "def", "abc!def" for the text abc!def. The idea is to replace the Punctuation char by **WhiteSpace PunctChar WhiteSpace** so that it will be preserved as a separate token in index. To achieve this i am trying a char\_filter as follows  
char\_filter :  
my\_char\_filter:  
type : pattern\_replace  
pattern : "(?\<=\p{Punct})"  
replacement: " Space OriginalPunctuationChar Space "  
The pattern tokenizer able to match the punctuation char , But how to get the matched character for replacement. Or any other suggestion to achieve the same ?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 16, 2017, 4:31am UTC](https://discuss.elastic.co/t/patternreplacecharfilter-and-punctuation-characters/75271/2 "2017-03-16T04:31:13Z")

</div>

Closed on March 16, 2017, 4:31am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
