私はURLを持っています:
url = "http://timesofindia.feedsportal.com/fy/8at2EuL0ihSIb3s7/story01.htmA"
最後に A、TRE などの不要な文字がいくつかあります。これを削除したいので、URLは次のようになります。
url = http://timesofindia.feedsportal.com/fy/8at2EuL0ihSIb3s7/story01.htm
どうすれば削除できますか?
私はURLを持っています:
url = "http://timesofindia.feedsportal.com/fy/8at2EuL0ihSIb3s7/story01.htmA"
最後に A、TRE などの不要な文字がいくつかあります。これを削除したいので、URLは次のようになります。
url = http://timesofindia.feedsportal.com/fy/8at2EuL0ihSIb3s7/story01.htm
どうすれば削除できますか?
URL が常に で終わる場合.htm
、.apsx
または.php
単純な正規表現で解決できる場合:
url = url[/^(.+\.(htm|aspx|php))(:?.*)$/, 1]
ここ Rubular でテストします。
まず、このメソッドを使用して部分文字列を取得します。スライスのように機能します。次に正規表現です。左から右へ:
^ # Start of line
( # Capture everything wanted enclosed
.+ # 1 or more of any character
\. # With a dot after it
(htm|aspx|php) # htm or aspx or php
) # Close url asked in question
( # Capture undesirable part
:? # Optional
.* # 0 or more any character
) # Close undesirable part
$ # End of line