从字符串中删除前导和跟踪

时间:2017-09-26 22:43:31

标签: javascript angular typescript

我使用typescript中的一些逻辑将protected $middlewareGroups = [ 'web' => [ \App\Http\Middleware\EncryptCookies::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Session\Middleware\StartSession::class, // \Illuminate\Session\Middleware\AuthenticateSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, \App\Http\Middleware\VerifyCsrfToken::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, ], 'api' => [ 'throttle:60,1', 'bindings', ], ]; /** * The application's route middleware. * * These middleware may be assigned to groups or used individually. * * @var array */ protected $routeMiddleware = [ 'auth' => \Illuminate\Auth\Middleware\Authenticate::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 'can' => \Illuminate\Auth\Middleware\Authorize::class, 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, ]; 插入到字符串中。 我想在字符串的开头和结尾删除<br>。其他人应该保持原样。 最好的方法是什么?

我使用<br>

实现了它

想知道这是否是最佳方式。

它有点复杂..应该在字符串的开头和字符串的结尾处替换所有的字符。

mystring.substring(mystring.indexOf('<br>'),mystring.lastIndexOf('<br>'))

1 个答案:

答案 0 :(得分:1)

要做到这一点,你可以使用它(在当地确认),

mystring.replace(/(^(<br>)+)|((<br>)+$)/g, '')

有关详细信息,请参阅this。希望它有所帮助。