简体   繁体   中英

Regex to match the last character if it is a dot

In OpenOffice Calc how do I remove the last character if it is a dot?

Example:

dog
cat.
rabbit

It becomes:

dog
cat
rabbit

What regex would you use to obtain that?

Regular expression:

  • To match a . , you have to write \\. , because . has a special meaning in regular expressions.
  • To match the end of the line, you have to write $ .

Putting it all together, I would use this regular expression: \\.$ . This will match a dot if it's at the end of the line. Demo

Removing the matched dots:

  1. Open "Find & Replace" window by pressing Ctrl+H
  2. Type regular expression from above into "Search for" field, this is what you want to be replaced
  3. Leave "Replace with" field empty, as you want to replace with nothing , which means it will remove the matched content (the dots)
  4. Under "More/Other options" , turn on "Regular expressions "*
  5. Click on "Replace" or "Replace all" button to perform the replacements

Please see documentation of this Calc feature for further details.

在OpenOffice Calc中,如果最后一个字符是点,该如何删除?

=IF(RIGHT(A1)=".";LEFT(A1;LEN(A1)-1);A1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM