Check for a substring at the end of string

Rohan Dalvi

Let's say I have two strings:

  1. "This-Test has a "
  2. "This has a-Test"

How do I match the "Test" at the end of string and only get the second as a result and not the first string. I am using include? but it will match all occurrences and not just the ones where the substring occurs at the end of string.

struthersneil

You can do this very simply using end_with?, e.g.

"Test something Test".end_with? 'Test'

Or, you can use a regex that matches the end of the string:

/Test$/ === "Test something Test"

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

修改string.Substring

来自分类Dev

Substring depending on Delimiter in the string

来自分类Dev

String.Substring解释

来自分类Dev

splitting a string if a substring has occured

来自分类Dev

Count number of a substring repetition in a string

来自分类Dev

How to check if a substring contains all of the letters in "apple"

来自分类Dev

C#string.Substring()或string.Remove()

来自分类Dev

String.substring()复制基础char []值

来自分类Dev

循环内的java string.Substring StringIndexOutOfBoundsException

来自分类Dev

Delete a substring from a string with a filename in Perl

来自分类Dev

Pulling variable length substring from middle of string

来自分类Dev

某些输入时String.Substring()崩溃

来自分类Dev

.NET 到 Delphi(string.Substring 函数)

来自分类Dev

C#中string.Split()与string.Substring()的效率?

来自分类Dev

StringIndexOutOfBoundsException:String.substring()和String.indexOf()问题

来自分类Dev

Javascript: String search for regex, starting at the end of the string

来自分类Dev

当substring只是换行符时,string.find(substring)函数返回什么?

来自分类Dev

C#String.Substring是否等效于StringBuilder?

来自分类Dev

如何检测String.substring是否复制字符数据

来自分类Dev

Index and length must refer to a location within the string error in substring

来自分类Dev

java String类中subSequence和subString方法之间的区别

来自分类Dev

正确使用SQL String_Split和Substring函数

来自分类Dev

string.substring在我的字符串上失败

来自分类Dev

正则表达式匹配 string#substring

来自分类Dev

Postgres query to check a string is a number

来自分类Dev

How to check if string character is a space?

来自分类Dev

Check if some string is in SQLite database

来自分类Dev

Hashcode to check uniqueness in a string array

来自分类Dev

Check if string exists in a text file

Related 相关文章

  1. 1

    修改string.Substring

  2. 2

    Substring depending on Delimiter in the string

  3. 3

    String.Substring解释

  4. 4

    splitting a string if a substring has occured

  5. 5

    Count number of a substring repetition in a string

  6. 6

    How to check if a substring contains all of the letters in "apple"

  7. 7

    C#string.Substring()或string.Remove()

  8. 8

    String.substring()复制基础char []值

  9. 9

    循环内的java string.Substring StringIndexOutOfBoundsException

  10. 10

    Delete a substring from a string with a filename in Perl

  11. 11

    Pulling variable length substring from middle of string

  12. 12

    某些输入时String.Substring()崩溃

  13. 13

    .NET 到 Delphi(string.Substring 函数)

  14. 14

    C#中string.Split()与string.Substring()的效率?

  15. 15

    StringIndexOutOfBoundsException:String.substring()和String.indexOf()问题

  16. 16

    Javascript: String search for regex, starting at the end of the string

  17. 17

    当substring只是换行符时,string.find(substring)函数返回什么?

  18. 18

    C#String.Substring是否等效于StringBuilder?

  19. 19

    如何检测String.substring是否复制字符数据

  20. 20

    Index and length must refer to a location within the string error in substring

  21. 21

    java String类中subSequence和subString方法之间的区别

  22. 22

    正确使用SQL String_Split和Substring函数

  23. 23

    string.substring在我的字符串上失败

  24. 24

    正则表达式匹配 string#substring

  25. 25

    Postgres query to check a string is a number

  26. 26

    How to check if string character is a space?

  27. 27

    Check if some string is in SQLite database

  28. 28

    Hashcode to check uniqueness in a string array

  29. 29

    Check if string exists in a text file

热门标签

归档